Python ValueError:无法为张量u';输入形状的值;占位符_1:0';,哪个有形状
我正在尝试运行以下代码以对MNIST图像进行分类:Python ValueError:无法为张量u';输入形状的值;占位符_1:0';,哪个有形状,python,tensorflow,Python,Tensorflow,我正在尝试运行以下代码以对MNIST图像进行分类: import random import input_data mnist = input_data.read_data_sets(raw_input(), raw_input(), raw_input()) import tensorflow as tf x = tf.placeholder(tf.float32, [None, 784]) W = tf.Variable(tf.zeros([784, 10])) b = tf.Vari
import random
import input_data
mnist = input_data.read_data_sets(raw_input(), raw_input(), raw_input())
import tensorflow as tf
x = tf.placeholder(tf.float32, [None, 784])
W = tf.Variable(tf.zeros([784, 10]))
b = tf.Variable(tf.zeros([10]))
y = tf.nn.softmax(tf.matmul(x, W) + b)
y_ = tf.placeholder(tf.float32, [None, 10])
cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(y), reduction_indices=[1]))
train_step = tf.train.GradientDescentOptimizer(0.05).minimize(cross_entropy)
sess = tf.InteractiveSession()
tf.initialize_all_variables().run()
for _ in range(1000):
batch_xs, batch_ys = mnist.train.next_batch(100)
sess.run(train_step, feed_dict={x: batch_xs, y_: batch_ys})
correct_prediction = tf.equal(tf.argmax(y,1), tf.argmax(y_,1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
print(sess.run(accuracy, feed_dict={x: mnist.test.images, y_: mnist.test.labels}))
前3行是我正在做的练习中给出的,其余的行是我从Tensorflow教程中复制的
问题是我越来越
ValueError: Cannot feed value of shape (1000, 28, 28, 1) for Tensor u'Placeholder_1:0', which has shape (Dimension(None), Dimension(10))
在最后一行
我认为问题在于mnist
对象。它的类型是input\u data.DataSets
,但我不知道里面是什么,也不知道如何检查里面是什么
如果我运行print(mnist.test.labels)
,我会得到[[0]
,这非常混乱
您知道如何修复此代码吗?您正在向占位符提供不正确的形状数据。“mnist”到底在做什么?从哪里获得的?通常,这是用于下载mnist的文件“”。其调用如TF MNIST示例所示:您能提供输入数据函数/文件的代码吗?您正在向占位符提供不正确的形状数据。“MNIST”到底在做什么?从何处获得的?通常,这是用于下载MNIST的文件“”它的调用如TF MNIST示例所示:您能提供您的输入\数据函数/文件的代码吗?