【问题标题】:How can I test the Deep MNIST for Experts code on a single image?如何在单个图像上测试 Deep MNIST for Experts 代码?
【发布时间】: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


【解决方案1】:

您的图表中某处有一个占位符,您没有提供该占位符。您的 feed_dict 中可能需要另一个 x 用于其他网络。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-07-27
    • 2018-04-02
    • 1970-01-01
    • 2017-12-06
    • 2015-06-21
    • 2017-02-18
    • 1970-01-01
    相关资源
    最近更新 更多