How to display test images with prediction

时间:2017-11-12 22:32:15

标签: tensorflow deep-learning

I want display my test images with predicted label for it.

train_step.run(feed_dict={x: images32, y_: one_hot_lables})
correct_prediction = tf.equal(tf.argmax(y, 1), tf.argmax(y_, 1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))

print(accuracy.eval(feed_dict={x: test_images32, y_: T_one_hot_lables}))

I only print result, but i want display every images in test_images32 and predicted label

1 个答案:

答案 0 :(得分:0)

这自然取决于数据的形状,但对于一般的深度学习问题,我使用matplotlib使用以下方法。您可能希望使用plt.ion()对此进行扩展以使其具有交互性,并在显示每个图像后等待。

import matplotlib.pyplot as plt

predictions = sess.run(y, {feed_dict={x: test_images32}})
for i, image in enumerate(test_images32):
     plt.imshow(image) # depending on being RGB or gray this might need to be reshaped
     print(np.argmax(predictions[i]))