Making predictions with a TensorFlow model

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.

Leave a Comment