这个问题专门针对Google MNIST教程 ,该教程定义了一个预测变量,但没有应用它。根据乔纳森·惠(Jonathan Hui)的TensorFlow Estimator博客文章的指导 ,以下代码完全适合Google教程并进行预测:
from matplotlib import pyplot as plt
images = mnist.test.images[0:10]
predict_input_fn = tf.estimator.inputs.numpy_input_fn(
x={"x":images},
num_epochs=1,
shuffle=False)
mnist_classifier.predict(input_fn=predict_input_fn)
for image,p in zip(images,mnist_classifier.predict(input_fn=predict_input_fn)):
print(np.argmax(p['probabilities']))
plt.imshow(image.reshape(28, 28), cmap=plt.cm.binary)
plt.show()
0
我遵循了给定的mnist教程,并且能够训练模型并评估其准确性。但是,这些教程没有显示如何在给定模型的情况下进行预测。我对准确性不感兴趣,我只想使用模型预测一个新示例,然后在输出中查看所有结果(标签),每个结果都有其分配的分数(排序或不排序)。