我试图在Jupyter笔记本中运行以下代码,但是我得到了InvalidArgumentError
的placeholder
。Tensorflow:占位符InvalidArgumentError
但是,当我编写一个Python脚本并在命令窗口中运行它时,它工作。我想知道如何成功地在笔记本中运行我的代码,谢谢。
- OS:Ubuntu的16.04 LTS
- Tensorflow版本:0.12rc(从源安装)
程序和输出:
命令窗口:
实际活动代码:
import tensorflow as tf
import numpy as np
raw_data = np.random.normal(10, 1, 100)
# Define alpha as a constant
alpha = tf.constant(0.05)
# A placeholder is just like a variable, but the value is injected from the
# session
curr_value = tf.placeholder(tf.float32)
# Initialize the previous average to some
prev_avg = tf.Variable(0.)
avg_hist = tf.summary.scalar("running_average", update_avg)
value_hist = tf.summary.scalar("incoming_values", curr_value)
merged = tf.summary.merge_all()
writer = tf.summary.FileWriter("./logs")
init = tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init)
for i in range(len(raw_data)):
summary_str, curr_avg = sess.run([merged, update_avg], feed_dict={curr_value: raw_data[i]})
sess.run(tf.assign(prev_avg, curr_avg))
print(raw_data[i], curr_avg)
writer.add_summary(summary_str, i)
欢迎来到SO。请将实际的代码文本放在您的问题中,而不是截图。 http://stackoverflow.com/help/how-to-ask –