我試圖在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 –