【发布时间】:2018-01-10 06:22:10
【问题描述】:
我刚开始使用 tensorflow,我想在我自己的图像上测试来自 tensorflow 的 tutorial 的训练模型。这是我在教程开始时在自己的图像上测试 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,但它给了我这个错误:
InvalidArgumentError:您必须为占位符张量提供一个值 'Placeholder_2' 与 dtype 浮动 [[节点:Placeholder_2 = Placeholderdtype=DT_FLOAT, shape=, _device="/job:localhost/replica:0/task:0/cpu:0"]]
【问题讨论】:
-
给你的占位符命名,这样就很容易调试了。
标签: tensorflow deep-learning mnist