0

I am new to tensorflow and i have a quick question, here is the code of my model for MNIST

def neural_network_model(data): hidden_1_layer = {'weights': tf.Variable(tf.random_normal([784, n_nodes_hl1])), 'biases': tf.Variable(tf.random_normal([n_nodes_hl1]))} hidden_2_layer = {'weights': tf.Variable(tf.random_normal([n_nodes_hl1, n_nodes_hl2])), 'biases': tf.Variable(tf.random_normal([n_nodes_hl2]))} hidden_3_layer = {'weights': tf.Variable(tf.random_normal([n_nodes_hl2, n_nodes_hl3])), 'biases': tf.Variable(tf.random_normal([n_nodes_hl3]))} output_layer = {'weights': tf.Variable(tf.random_normal([n_nodes_hl3, n_classes])), 'biases': tf.Variable(tf.random_normal([n_classes])), } l1 = tf.add( tf.matmul( data, hidden_1_layer['weights']), hidden_1_layer['biases']) l1 = tf.nn.relu(l1) l2 = tf.add( tf.matmul( l1, hidden_2_layer['weights']), hidden_2_layer['biases']) l2 = tf.nn.relu(l2) l3 = tf.add( tf.matmul( l2, hidden_3_layer['weights']), hidden_3_layer['biases']) l3 = tf.nn.relu(l3) output = tf.matmul(l3, output_layer['weights']) + output_layer['biases'] return output 

my question is that does this function represents the output values for input 'data' ? or this function represents a complete model that will be used for testing / predicting images after training?

Here is the code that I used for prediction of a particular image :

prediction=neural_network_model(mnist_training_data_set) p=tf.argmax(prediction,1) print(p.eval(feed_dict={x: i}, session=sess)) 

So here I am confused , whether that function is a model or returns only predicted outputs. Can anyone explain, Thanks

3
  • Does this code run? Can you provide the full code in a format that lets me run it? (e.g. Github) Commented Jul 6, 2017 at 18:18
  • yes the code works , but my question is related to the model that is made Commented Jul 6, 2017 at 18:21
  • this function is said to be trained model as well as the output of input images also ? Commented Jul 6, 2017 at 18:22

1 Answer 1

2

This function creates the model and adds it to the computation graph. The predicted outputs will be returned by the p.eval(feed_dict={x: i}, session=sess) line.

As such, the function returns the output layer of the model, which is what you will use to make predictions. Arguably you could call this the "model", but I think that it would be better to call the session variable the "model".

Sign up to request clarification or add additional context in comments.

3 Comments

what does this mean ? prediction=neural_network_model(mnist_training_data_set)
what does prediction variable gets ? after function call
It means that the value you are predicting is equal to output, the output layer of the neural network that you are defining inside the function.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.