【问题标题】:Invalid output Tensor index: 1 when running a custom yolov3-tiny model on Google's TFLite Object Detection exampleInvalid output Tensor index: 1 when running a custom yolov3-tiny model on Google's TFLite Object Detection example
【发布时间】:2020-05-26 15:03:34
【问题描述】:

尝试在 TensorFlow Lite's Object Detection Android Demo 上运行 tiny-yolov3 模型时遇到错误。 当我尝试在手机上运行应用程序时,应用程序崩溃并出现以下错误

E/AndroidRuntime: FATAL EXCEPTION: inference
    Process: org.tensorflow.lite.examples.detection, PID: 5535
    java.lang.IllegalArgumentException: Invalid output Tensor index: 1
        at org.tensorflow.lite.NativeInterpreterWrapper.getOutputTensor(NativeInterpreterWrapper.java:292)
        at org.tensorflow.lite.NativeInterpreterWrapper.run(NativeInterpreterWrapper.java:166)
        at org.tensorflow.lite.Interpreter.runForMultipleInputsOutputs(Interpreter.java:314)
        at org.tensorflow.lite.examples.detection.tflite.TFLiteObjectDetectionAPIModel.recognizeImage(TFLiteObjectDetectionAPIModel.java:204)
        at org.tensorflow.lite.examples.detection.DetectorActivity$2.run(DetectorActivity.java:181)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:214)
        at android.os.HandlerThread.run(HandlerThread.java:65)

Here 是我的 tflite 和标签文件。

我在 DetectorActivity.java 上更改了以下内容以避免出现this 错误

TF_OD_API_INPUT_SIZE from 300 to 416
TF_OD_API_IS_QUANTIZED from true to false

然后我在 TFLiteObjectDetectionAPIModel.java 上更改了以下内容

NUM_DETECTIONS from 10 to 2535
d.outputLocations = new float[1][NUM_DETECTIONS][4] to d.outputLocations = new float[1][NUM_DETECTIONS][7];

Here是我使用的 DetectorActivity.java 和 TFLiteObjectDetectionAPIModel.java

Here 是我的模型 .weight、cfg 和 .pb(如果需要)

任何帮助将不胜感激

【问题讨论】:

    标签: android tensorflow tensorflow-lite


    【解决方案1】:

    我可以使用您的自定义模型和源代码重现该问题。感谢您提供它们。

    主要问题是您的自定义 detect.tflite 模型的输出规范与对象检测示例应用所期望的不同。

    您可以使用模型可视化工具(例如 netron)查看差异。

    示例应用 (mobilenet_ssd) 使用的原始模型如下所示:

    如您所见,有 4 个标量 float32 输出,它们本质上是从最终的 TFLite_Detection_PostProcess 节点中分离出来的。

    另一方面,您的模型有一个 [1,2535,7] 形状的输出张量。

    因此,当应用程序的 Java 代码运行 tfLite.runForMultipleInputsOutputs(inputArray, outputMap) 时,它会尝试根据您在 outputMap 中输入的内容分配多个输出。但是,由于您的模型中只有一个输出张量,因此当它尝试将索引 1 处的输出分配到 outputClasses 数组时,它会失败并显示错误消息。

    我不太了解 yolov3 模型的详细信息,无法帮助您使用用于转换模型的确切命令,但this doc 应该提供有关如何转换原始模型的更详细信息。

    【讨论】:

    • 非常感谢您的详细回答。您认为问题出在转换方法上吗?还是您认为 yolov3-tiny 完全无法与 tf-lite 一起使用?
    • 我会说你非常接近让它工作。通常,模型转换过程是最大的障碍,只要你有一个工作的 TFLite 模型,在应用程序中使用它应该相对简单。此时,您应该尝试调整转换参数以使其与预期的输出格式匹配,或者修改应用程序代码以按原样读取模型的输出张量,并根据输出张量从输出张量中提取检测到的对象yolov3-tiny 模型输出规格。
    • 嘿,你解决过这个问题吗?我有一个非常相似的问题
    猜你喜欢
    • 2022-12-01
    • 2013-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-09
    • 2022-12-27
    相关资源
    最近更新 更多