繁体   English   中英

提供占位符时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”提供明确的名称,因此默认名称为“占位符”,因此应按以下方式进行输入:

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})

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM