Daniyal Javaid
Daniyal Javaid

Reputation: 1626

MNIST image prediction model

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

Upvotes: 0

Views: 214

Answers (1)

finbarr
finbarr

Reputation: 759

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".

Upvotes: 2

Related Questions