如何在单个图像上测试面向专家的深度 MNIST 代码?



我刚刚开始使用张量流,我想在我自己的图像上测试tensorflow教程中训练好的模型。这是我在本教程开始时在我自己的图像上测试 Softmax 回归模型时使用的代码:

with open("three.jpeg", "rb") as f:
contents = f.read()
image = tf.image.decode_jpeg(contents, channels=1)
image_float = tf.image.convert_image_dtype(image, tf.float32)
resized_image = tf.image.resize_images(image_float, [28, 28])
resized_image = tf.reshape(resized_image, [784])
img = 1 - resized_image.eval() 
classification = sess.run(tf.argmax(y, 1), feed_dict={x: [img]})
plt.imshow(img.reshape(28, 28), cmap=plt.cm.binary)
plt.show()
print ('NN predicted', classification[0])

这对于softmax函数工作正常,但不适用于多层卷积网络。我尝试更改此行中的y

classification = sess.run(tf.argmax(y, 1), feed_dict={x: [img]})

y_conv但它给了我这个错误:

无效参数错误:您必须为占位符张量输入值 带有 dtype 浮点数的"Placeholder_2" [[节点: Placeholder_2 = 占位符类型=DT_FLOAT, 形状=, _device="/作业:本地主机/副本:0/任务:0/CPU:0"]]

图表中的某个地方有一个占位符,您没有喂食。对于另一个网络,您的feed_dict中可能需要另一个x

最新更新