尝试在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和labelfile。
我在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(如果需要)
任何帮助将不胜感激
答案 0 :(得分:0)
我可以使用您的自定义模型和源代码来重现该问题。感谢您提供它们。
主要问题是您的自定义detect.tflite
模型的输出规范与对象检测示例应用程序期望的规范不同。
您可以使用模型可视化工具(例如netron)来查看差异。
示例应用程序(mobilenet_ssd)使用的原始模型如下:
如您所见,有4个标量float32输出,它们基本上是从最后的TFLite_Detection_PostProcess
节点拆分出来的。
另一方面,您的模型具有[1,2535,7]形状的单个输出张量。
因此,当应用的Java代码运行tfLite.runForMultipleInputsOutputs(inputArray, outputMap)
时,它将尝试根据您在outputMap
中放置的内容来分配多个输出。但是,由于模型中只有一个输出张量,因此当它尝试将索引1处的输出分配到outputClasses
数组中时,它将失败并显示错误消息。
我不了解有关yolov3模型的足够详细信息,无法为您提供用于转换模型的确切命令,但是this doc应该提供有关如何转换原始模型的更多详细信息。