无效的输出Tensor指数。在谷歌的TFLite对象检测示例上运行自定义yolov3-tiny模型时,输出指数为1。

问题描述 投票:0回答:1

当我试图在以下设备上运行 tiny-yolov3 模型时,我遇到了一个错误。TensorFlow Lite的对象检测Android演示.当我试图在手机上运行该应用程序时,该应用程序崩溃,并出现以下错误

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)

的tflite和labelfile。

我在DetectorActivity.java上修改了以下内容以避免 这个 错误

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];

的DetectorActivity.java和TFLiteObjectDetectionAPIModel.java,我用的是

这是我的模型.重量,cfg,和.pb,如果需要的话。

恳请协助

android tensorflow tensorflow-lite tf-lite
1个回答
0
投票

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

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

你可以使用模型可视化器,如 网龙.

例子应用(mobilenet_ssd)使用的原始模型是这样的。

enter image description here

正如你所看到的,有4个标量float32输出,它们基本上是从最终的 TFLite_Detection_PostProcess 节点。

enter image description here

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

enter image description here

所以当应用程序的Java代码运行 tfLite.runForMultipleInputsOutputs(inputArray, outputMap),它试图根据你放在 outputMap. 然而,由于您的模型中只有一个输出张量,当它试图将索引1的输出分配到 outputClasses 数组,它的错误信息是失败的。

我对yolov3模型的细节不够了解,无法帮你找到转换模型的准确命令,但我可以告诉你 本文件 应更详细地说明原始模型是如何转换的。

© www.soinside.com 2019 - 2024. All rights reserved.