我在学习张量流,通过尝试这个例子_软最大.py(this is the orignal file),我添加了一些修改,以便使用张力板:
tf.global_variables_initializer().run()
merged_summary_op = tf.summary.merge_all()
summary_writer = tf.summary.FileWriter('mnist_logs', sess.graph)
# Train
for i in range(1000):
batch_xs, batch_ys = mnist.train.next_batch(100)
sess.run(train_step, feed_dict={x: batch_xs, y_: batch_ys})
if i%25 == 0:
summary_str , _ = sess.run(merged_summary_op)
summary_writer.add_summary(summary_str,i)
# Test trained model
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}))
但我运行此文件时出现错误:
^{pr2}$如果有人能找出我写错的地方,我将不胜感激。在
我相信这个问题是一样的:Tensorflow TypeError: Fetch argument None has invalid type <type 'NoneType'>?
虽然代码中没有显示,但变量
train_step
的值可能是None
。打印出来检查一下。这是你的“fetch参数”,它是你要求tensorflow计算并返回给你的操作或张量。在在代码的早期,您可能有:
train_step = tf.train.AdamOptimizer(...).minimize(...)
Tensorflow需要您将此操作发送到
sess.run(...)
。这指示tensorflow计算train_step
“OP”,并在这样做时更新权重。在此过程中,train_step
可能被重新分配给None
。在相关问题 更多 >
编程相关推荐