为了想看一段代买的Tensor,加入了
sess = tf.Session()
print(sess.run(self.embedded_chars))
然后就报错:
InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'Placeholder_1' with dtype float
[[Node: Placeholder_1 = Placeholder[dtype=DT_FLOAT, shape=<unknown>, _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]
刚开始没找到错误,后来明白了。embedded_chars由两个量算得,但是都只定义了一个placeholder,没有赋值,所以得不到embedded_chars的值。例如(from https://github.com/tensorflow/tensorflow/issues/10632):
import tensorflow as tf
a = tf.placeholder(tf.float32)
b = tf.placeholder(tf.float32)
c = a + b
with tf.Session() as sess:
print(c.eval(feed_dict={a:1.0})) # I did not feed any value to
# `b` which is required for
# evaluating `c`
里面只定义了a,没有定义b的量,会产生同样的报错。
本文探讨了在TensorFlow中使用Placeholder时常见的错误——未正确赋值导致的运行时异常,并通过实例详细解释了解决方案。当在会话中尝试评估依赖于未赋值的Placeholder的张量时,会触发InvalidArgumentError。文章强调了在调用.eval()前,必须通过feed_dict参数为所有占位符提供值的重要性。
6114





