您的位置:首页 > Web前端

【Tensorflow】报错:Cannot interpret feed_dict key as Tensor: The name 'x' refers to an operation, # > no

2017-06-04 15:12 2006 查看
问题描述:

我尝试给一个tensor输入值的时候报错:

Cannot interpret feed_dict key as Tensor: The name 'x' refers to an operation,
not a Tensor. Tensor names must be of the form "<op_name>:<output_index>".


代码如下:

import tensorflow as tf
x = tf.placeholder(tf.float32, (None,), 'x')
y = tf.reduce_sum(x)
sess = tf.Session()

sess.run(y, {x: [1, 2, 3]}
# > 6.0

sess.run(y, {'x': [1, 2, 3]}
# > Cannot interpret feed_dict key as Tensor: The name 'x' refers to an operation,
# > not a Tensor. Tensor names must be of the form "<op_name>:<output_index>".

sess.run(y, {tf.get_default_graph().get_operation_by_name('x').outputs[0]: [1, 2, 3]})
# > 6.0有没有可能feed placeholders以他们的变量名呢?如果不能,为什么?这对随后从磁盘恢复网络后进行feed很有用。

问题解决:

你需要添加 ":0",例如:

print sess.run(y, {'x:0': [1, 2, 3]})

这里是为什么 ":0"要被加上的原因:http://stackoverflow.com/a/37870634/419116

.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐