之前我曾使用Supervisor会话来管理FIFOQueues而没有任何问题。但是,我遇到了下面简单代码的问题,这给了我错误信息:
InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'W' with dtype float [[Node: W = Placeholder[dtype=DT_FLOAT, shape=<unknown>, _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]
import tensorflow as tf
LOG_DIR = 'log/sv/'
def using_supervisor ():
with tf.Graph ().as_default ():
W = tf.placeholder (tf.float32, name = 'W')
W = tf.multiply (W, 100)
moving_mean = tf.random_normal (shape = [10], mean = W, stddev = 1)
tf.summary.histogram ("moving_mean", moving_mean)
summary_op = tf.summary.merge_all ()
sv = tf.train.Supervisor (logdir = LOG_DIR)
with sv.managed_session () as sess:
K = 2
for i in range (K):
result = sess.run (summary_op, feed_dict = {W: float (i)})
sess.close ()
#----------------------------------------
if __name__ == "__main__":
using_supervisor ()
有什么想法吗?
显然,没有合理的理由在这个简单的程序中使用监督会话,因为我没有利用它,只是混淆了为什么它没有工作。
答案 0 :(得分:0)
tf.train.Supervisor is deprecated!感谢tensorflow开发人员提供正确的警告信息!切换到tf.train.MonitoredSession,它可以工作!
import tensorflow as tf
LOG_DIR = 'log/'
def run ():
with tf.Graph ().as_default ():
W = tf.placeholder (tf.float32, name = 'W')
W = tf.multiply (W, 100)
moving_mean = tf.random_normal (shape = [10], mean = W, stddev = 1)
tf.summary.histogram ("moving_mean", moving_mean)
summary_op = tf.summary.merge_all ()
with tf.train.MonitoredTrainingSession () as sess:
K = 2
for i in range (K):
result = sess.run (summary_op, feed_dict = {W: float (i)})
#----------------------------------------
if __name__ == "__main__":
run ()