Making predictions with a TensorFlow model

user247866 picture user247866 · Nov 14, 2015 · Viewed 93.1k times · Source

I followed the given mnist tutorials and was able to train a model and evaluate its accuracy. However, the tutorials don't show how to make predictions given a model. I'm not interested in accuracy, I just want to use the model to predict a new example and in the output see all the results (labels), each with its assigned score (sorted or not).

Answer

dga picture dga · Nov 14, 2015

In the "Deep MNIST for Experts" example, see this line:

We can now implement our regression model. It only takes one line! We multiply the vectorized input images x by the weight matrix W, add the bias b, and compute the softmax probabilities that are assigned to each class.

y = tf.nn.softmax(tf.matmul(x,W) + b)

Just pull on node y and you'll have what you want.

feed_dict = {x: [your_image]}
classification = tf.run(y, feed_dict)
print classification

This applies to just about any model you create - you'll have computed the prediction probabilities as one of the last steps before computing the loss.