Jasper
Jasper

Reputation: 63

How to output the predicted value(label) in tensorflow MNIST tutorial?

In tensorflow's tutorial of MNIST, the last step is to output the test accuracy of the model using the following code:

# Test trained model
correct_prediction = tf.equal(tf.argmax(y, 1), tf.argmax(y_, 1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
print(sess.run(accuracy, feed_dict={x: mnist.test.images,
                                  y_: mnist.test.labels}))

However, I was wondering how can I modify this code to output the predicted value(label) of the test set, instead of just printing out the accuracy?

Here's the link of the tutorial: https://www.tensorflow.org/tutorials/mnist/beginners/

Upvotes: 3

Views: 6489

Answers (1)

Daiver
Daiver

Reputation: 1508

Something like this should work

print(sess.run(tf.argmax(y, 1), feed_dict={x: mnist.test.images}))

Because y in tutorial is tensor where column with index j describes how likely image in row i is number j, so tf.argmax just returns index of column with highest probability for each row.

PS Sorry for my English

Upvotes: 6

Related Questions