【问题标题】:How to have multiple outputs in a tensorflow SavedModel?如何在张量流 SavedModel 中有多个输出?
【发布时间】:2020-05-03 13:00:58
【问题描述】:

所以整个故事是我正在尝试将 .pb 冻结推理图转换为 tflite 模型,为此我首先尝试创建 SavedModel。这是我在下面尝试使用的代码:

with tf.Session(graph=tf.Graph()) as sess:
    # name="" is important to ensure we don't get spurious prefixing
    tf.import_graph_def(graph_def, name="")
    g = tf.get_default_graph()
    inp = g.get_tensor_by_name("image_tensor:0")

    out = {{g.get_tensor_by_name('num_detections:0')}, {g.get_tensor_by_name('detection_boxes:0')},{g.get_tensor_by_name('detection_scores:0')},{g.get_tensor_by_name('detection_classes:0')}}


    sigs[signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY] = \
        tf.saved_model.signature_def_utils.predict_signature_def(
            {"inputs": inp}, {"outputs": out})

    builder.add_meta_graph_and_variables(sess,
                                         [tag_constants.SERVING],
                                         signature_def_map=sigs)

builder.save()

我没有正确地“输出”,但是我不知道如何为 SavedModel 签名包含更多输出,或者是否有可能?

【问题讨论】:

    标签: python tensorflow


    【解决方案1】:

    我认为,您需要在该字典中指定所有单独的输出张量,而不是向输出字典提供集合。像这样的东西对我有用。

    with tf.Session(graph=tf.Graph()) as sess:
        # name="" is important to ensure we don't get spurious prefixing
        tf.import_graph_def(graph_def, name="")
        g = tf.get_default_graph()
        inp = g.get_tensor_by_name("input_image:0")
        out1 = g.get_tensor_by_name("output_1:0")
        out2 = g.get_tensor_by_name("output_2:0")
        out3 = g.get_tensor_by_name("output_3:0")
        sigs[signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY] = \
            tf.saved_model.signature_def_utils.predict_signature_def(
                {"in": inp}, {"out1": out1, "out2": out2, "out3": out3 })
    
        builder.add_meta_graph_and_variables(sess,
                                             [tag_constants.SERVING],
                                             signature_def_map=sigs)
    
        builder.save()
    

    我还在学习 TF,但希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-13
      • 2021-05-05
      • 1970-01-01
      • 2020-04-09
      • 1970-01-01
      • 2020-03-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多