【问题标题】:Cannot interpret feed_dict key as Tensor无法将 feed_dict 键解释为张量
【发布时间】:2018-11-14 18:37:38
【问题描述】:

我有一个名为“enqueue_ops”的占位符列表和一个名为“feed_fns”的方法列表,每个方法都返回一个 feed_dict。

我的图表的队列运行器定义为:

queue_runner = feeding_queue_runner.FeedingQueueRunner(
            queue=queue, enqueue_ops=enqueue_ops,
            feed_fns=feed_fns)

但是我得到了一个错误

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

但是为什么他们查看我的 feed_dict 键,而我的 feed_dict 值是他们不想查看的张量?

谢谢!!!

【问题讨论】:

  • 您应该添加引发错误的代码,但似乎您需要在张量名称的末尾添加“:0”,例如"face_detection/x1:0"

标签: tensorflow


【解决方案1】:

在 tensorflow 中,如果你想恢复一个图并使用它,在保存图之前你应该给你想要的变量、占位符、操作等一个唯一的名称。

示例见下文。

W = tf.Variable(0.1, name='W')
X = tf.placeholder(tf.float32, (None, 2), name='X')
mult = tf.multiply(W,X,name='mult')

然后,保存图表后,您可以按如下方式恢复和使用它。请记住将张量与引号捆绑在一起。如果您要查找张量的值,请在张量名称的末尾添加:0,因为 tensorflow 要求它采用“op_name:output_index”格式。

with tf.Session() as sess:
    new_saver = tf.train.import_meta_graph('your_model.meta')
    new_saver.restore(sess, tf.train.latest_checkpoint('./'))
    print(sess.run('mult:0', feed_dict={'X:0': [[1,4],[2,9]]}))

【讨论】:

    猜你喜欢
    • 2017-04-08
    • 1970-01-01
    • 1970-01-01
    • 2017-08-06
    • 1970-01-01
    • 2017-07-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多