[英]Tensorflow: InvalidArgumentError when feeding numpy ndarray to placeholder
[英]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.