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

问题描述:

我尝试给一个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
.

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值