當我試圖完成與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)的類型引起的。
關於如何解決這個問題的任何建議?
你是對的,這是我的錯傳遞'y',而不是'y_'到'accuracy.eval' call.Thanks的feed_dict很多。 –
不客氣!由於我的答案解決了您的問題,請記住將其標記爲已接受 – nessuno