2017-05-28 26 views
0

当我试图完成与tensorflow SOFTMAX回归,发生了一些问题,如下:InvalidArgumentError

tensorflow.python.framework.errors_impl.InvalidArgumentError:
You must feed a value for placeholder tensor 'Placeholder_1' with dtype float [[Node: Placeholder_1 = Placeholderdtype=DT_FLOAT, shape=[], _device="/job:localhost/replica:0/task:0/cpu:0"]]

从以上的描述中,据我所知,该问题是一个参数类型的错误。但在我的代码中,我的数据类型与占位符相同。

import tensorflow as tf 
from tensorflow.examples.tutorials.mnist import input_data 

m = input_data.read_data_sets("MNIST_data/", one_hot=True) 
sess = tf.InteractiveSession() 

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.5).minimize(cross_entropy) 
tf.global_variables_initializer() 

for i in range(1000): 
    batch_xs, batch_ys = m.train.next_batch(100) 
    train_step.run({x: batch_xs, y: batch_ys}) 

correct_prediction = tf.equal(tf.arg_max(y, 1), tf.arg_max(y_, 1)) 
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32)) 
print(accuracy.eval({x: m.test.images, y: m.test.labels})) 

我认为这个问题是由batch_xs(FLOAT32)和batch_ys(FLOAT32)的类型引起的。

关于如何解决这个问题的任何建议?

回答

1

该问题是由于您将y而不是y_传递到accuracy.eval调用的feed_dict中导致的。

通过这种方式,您将覆盖y的值,并且不使用占位符y_

只要改变行

print(accuracy.eval({x: m.test.images, y_: m.test.labels})) 
+0

你是对的,这是我的错传递'y',而不是'y_'到'accuracy.eval' call.Thanks的feed_dict很多。 –

+0

不客气!由于我的答案解决了您的问题,请记住将其标记为已接受 – nessuno

相关问题