【问题标题】:TF model input node not found in android在android中找不到TF模型输入节点
【发布时间】:2018-04-14 17:48:27
【问题描述】:

我训练了一个 hair_recognition 模型(.pb 文件)。它适用于 python 代码。输入节点是'hair_recognition/input_1' 但是当我在android中使用模型时,我得到以下错误:

java.lang.IllegalArgumentException: No Operation named [hair_recognition/input_1]

我已经通过在 Python 和 Android 中打印节点名称来调试模型。但无法找出原因。 关于可能导致此行为的任何建议?

代码 - 加载模型和获取输入张量节点

Python:

 with tf.gfile.GFile(pb_file, "rb") as f:
        graph_def = tf.GraphDef()
        graph_def.ParseFromString(f.read())

    with tf.Graph().as_default() as ')graph:
        tf.import_graph_def(graph_def, name='hair_recognition')

 for op in graph.get_operations():
        print(op.name)

    x = graph.get_tensor_by_name('hair_recognition/input_1:0')

安卓:

inferenceInterface.feed(
                INPUT_NODE, floatValues, 1, bitmap.getWidth(), bitmap.getHeight(), 3);

【问题讨论】:

    标签: android python tensorflow


    【解决方案1】:

    我自己之前也遇到过类似的问题。 原因是您在 python 中使用前缀字符串 - hair_recognition 加载模型。所以你的输入张量有这个名字。 将前缀更改为其他值,例如“。”或空字符串。在这种情况下它也应该可以工作。

    在 Android 中,将 input_1:0 而非 hair_recognition/input_1:0 传递给 INPUT_NODE。并且错误应该得到解决。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-20
      • 1970-01-01
      • 2022-12-15
      • 2014-07-22
      • 2022-07-20
      • 2021-01-06
      • 1970-01-01
      • 2021-06-25
      相关资源
      最近更新 更多