【问题标题】:KeyError: "The name 'loss:0' refers to a Tensor which does not exist. The operation, 'loss', does not exist in the graph."KeyError:“名称‘loss:0’指的是一个不存在的张量。操作‘loss’在图中不存在。”
【发布时间】:2018-12-27 17:05:27
【问题描述】:

KeyError: "名称 'loss:0' 指的 Tensor 不存在。操作 'loss' 在图中不存在。"

大家好,我在使用 tensorflow 模型时遇到了问题。代码在终端中编译时运行良好,但是当我尝试将其设为 python API 时,它显示上述错误

output_layer = 'loss:0'
input_node = 'Placeholder:0'

# Crop the center for the specified network_input_Size
augmented_image = crop_center(augmented_image, network_input_size, network_input_size)


with tf.Session() as sess:
    prob_tensor = sess.graph.get_tensor_by_name(output_layer)
    predictions = sess.run(prob_tensor, {input_node: [augmented_image] })

上面的代码是在说错误

prob_tensor = sess.graph.get_tensor_by_name(output_layer)

【问题讨论】:

  • 请问您解决了这个问题吗?运行此示例时遇到相同的问题:docs.microsoft.com/en-us/azure/cognitive-services/…
  • Bgr_image 是一个未定义的参数。将其替换为 augmented_image,因为这是我们对输入图像所做的最后一次修改。它现在对我有用。

标签: python python-3.x tensorflow tensorboard tensor


【解决方案1】:

不确定是否与您的案例相关,但我在尝试从 Azure 自定义视觉服务 here 运行示例时遇到了同样的错误消息。

问题是因为我在导入图表时给了它一个名称 - 但应该在此处将其保留为空字符串:tf.import_graph_def(graph_def, name='')

【讨论】:

    【解决方案2】:

    我在使用从 Azure 自定义视觉服务导出的模型时遇到了同样的问题。在我的情况下,将输出张量的名称从“损失”更改为“模型输出”有效:

    output_layer = 'model_outputs:0'
    

    【讨论】:

      【解决方案3】:

      我在导出自定义视觉模型时遇到了同样的问题。当我使用 model_outputs:0 它运行。然而,预测数组没有意义。当我在自定义视觉中测试模型时,我得到 4 个对象 Three cars and a truck

      但是预测数组的形状是 13X13X40

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-05-03
        • 2018-01-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-10-22
        • 2019-07-25
        相关资源
        最近更新 更多