提供占位符时出现 TensorFlow InvalidArgumentError
TensorFlow InvalidArgumentError when feeding a placeholder
我有这个占位符:
__y = tf.placeholder(tf.int32)
然后我在下面的代码中使用它:
self.session.run(tf.global_variables_initializer())
self.cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(labels=self.__y, logits=self.super_source))
opt = tf.train.GradientDescentOptimizer(0.1).minimize(self.cost)
not_important, c = self.session.run(opt, feed_dict={labels: label})
我收到这个错误:
InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'Placeholder' with dtype int32
[[Node: Placeholder = Placeholder[dtype=DT_INT32, shape=<unknown>, _device="/job:localhost/replica:0/task:0/gpu:0"]()]]
我不明白我收到的错误,所以我无法解决我的问题。有人可以至少向我解释一下发生了什么吗?
如果我将您的示例重写为:
import tensorflow as tf
__y = tf.placeholder(tf.int32)
with tf.Session() as session:
session.run(__y)
我遇到同样的错误:
InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'Placeholder' with dtype int32
[[Node: Placeholder = Placeholder[dtype=DT_INT32, shape=<unknown>, _device="/job:localhost/replica:0/task:0/cpu:0"]()]]
这里的问题是,由于您没有为“__y”提供明确的名称,因此已获得默认名称 'Placeholder',因此应按如下方式提供:
with tf.Session() as session:
print(session.run(__y, feed_dict={__y: 123}))
这个问题很愚蠢,我没有喂 __y:
not_important, c = self.session.run([optimizer, self.cost], feed_dict={self.__labels: label, self.__y: 3.0})
我有这个占位符:
__y = tf.placeholder(tf.int32)
然后我在下面的代码中使用它:
self.session.run(tf.global_variables_initializer())
self.cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(labels=self.__y, logits=self.super_source))
opt = tf.train.GradientDescentOptimizer(0.1).minimize(self.cost)
not_important, c = self.session.run(opt, feed_dict={labels: label})
我收到这个错误:
InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'Placeholder' with dtype int32
[[Node: Placeholder = Placeholder[dtype=DT_INT32, shape=<unknown>, _device="/job:localhost/replica:0/task:0/gpu:0"]()]]
我不明白我收到的错误,所以我无法解决我的问题。有人可以至少向我解释一下发生了什么吗?
如果我将您的示例重写为:
import tensorflow as tf
__y = tf.placeholder(tf.int32)
with tf.Session() as session:
session.run(__y)
我遇到同样的错误:
InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'Placeholder' with dtype int32
[[Node: Placeholder = Placeholder[dtype=DT_INT32, shape=<unknown>, _device="/job:localhost/replica:0/task:0/cpu:0"]()]]
这里的问题是,由于您没有为“__y”提供明确的名称,因此已获得默认名称 'Placeholder',因此应按如下方式提供:
with tf.Session() as session:
print(session.run(__y, feed_dict={__y: 123}))
这个问题很愚蠢,我没有喂 __y:
not_important, c = self.session.run([optimizer, self.cost], feed_dict={self.__labels: label, self.__y: 3.0})