簡體   English   中英

Tensorflow MNIST教程代碼錯誤

[英]Tensorflow MNIST tutorial code error

我已經在網上搜索了答案,但沒有幫助(其他人遇到的所有問題都歸因於語法或過時的tensorflow版本),所以我決定自問-我在這里。

我正在嘗試從Tensorflow MNIST教程中運行代碼:

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

mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)

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)

sess = tf.InteractiveSession()

tf.global_variables_initializer().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}))

結果我得到這個錯誤:

InvalidArgumentError: You must feed a value for placeholder tensor 
'Placeholder_6' with dtype float and shape [?,784]
 [[Node: Placeholder_6 = Placeholder[dtype=DT_FLOAT, shape=[?,784], 
_device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]

我的Tensorflow是1.4.0。 整個代碼似乎與教程中的代碼完全一樣。

似乎這是某種變量沖突:重新啟動我的IDE后,代碼最終沒有任何錯誤-我將其留給遇到同樣麻煩的人使用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM