我最近在Google Cloud Vision上训练了对象检测模型。我导出了metadat jason文件,标签文本文件和训练后的模型的模型tflite文件,并打算在Android上运行它。但是,由于每次崩溃,我无法使用Android演示应用程序运行该模型。
所使用的演示应用程序与经过本地培训和转换的tflite模型兼容,但与从Google Cloud导出的模型不兼容。
这里可能出什么问题,如何解决?
谢谢
参考:演示应用程序:https : //github.com/tensorflow/examples/tree/master/lite/examples/object_detection
部分日志:
2020-01-24 11:29:11.628 18071-18071/org.tensorflow.lite.examples.detection E/libc: Access denied finding property "persist.camera.privapp.list"
2020-01-24 11:29:11.732 18071-18101/org.tensorflow.lite.examples.detection I/tensorflow: CameraConnectionFragment: Opening camera preview: 640x480
2020-01-24 11:29:11.769 18071-18102/org.tensorflow.lite.examples.detection D/vndksupport: Loading /vendor/lib/hw/[email protected] from current namespace instead of sphal namespace.
2020-01-24 11:29:11.770 18071-18102/org.tensorflow.lite.examples.detection D/vndksupport: Loading /vendor/lib/hw/gralloc.msm8937.so from current namespace instead of sphal namespace.
2020-01-24 11:29:11.803 18071-18071/org.tensorflow.lite.examples.detection I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@5ab1c5e time:332335506
2020-01-24 11:29:12.198 18071-18101/org.tensorflow.lite.examples.detection D/tensorflow: CameraActivity: Initializing buffer 0 at size 307200
2020-01-24 11:29:12.201 18071-18101/org.tensorflow.lite.examples.detection D/tensorflow: CameraActivity: Initializing buffer 1 at size 153599
2020-01-24 11:29:12.203 18071-18101/org.tensorflow.lite.examples.detection D/tensorflow: CameraActivity: Initializing buffer 2 at size 153599
2020-01-24 11:29:12.204 18071-18101/org.tensorflow.lite.examples.detection I/tensorflow: DetectorActivity: Preparing image 1 for detection in bg thread.
2020-01-24 11:29:12.311 18071-18100/org.tensorflow.lite.examples.detection I/tensorflow: DetectorActivity: Running detection on image 1
2020-01-24 11:29:12.475 18071-18100/org.tensorflow.lite.examples.detection E/AndroidRuntime: FATAL EXCEPTION: inference
Process: org.tensorflow.lite.examples.detection, PID: 18071
java.lang.IllegalArgumentException: Cannot convert between a TensorFlowLite buffer with 307200 bytes and a Java Buffer with 270000 bytes.
at org.tensorflow.lite.Tensor.throwIfShapeIsIncompatible(Tensor.java:332)
at org.tensorflow.lite.Tensor.throwIfDataIsIncompatible(Tensor.java:305)
at org.tensorflow.lite.Tensor.setTo(Tensor.java:123)
at org.tensorflow.lite.NativeInterpreterWrapper.run(NativeInterpreterWrapper.java:148)
at org.tensorflow.lite.Interpreter.runForMultipleInputsOutputs(Interpreter.java:296)
at org.tensorflow.lite.examples.detection.tflite.TFLiteObjectDetectionAPIModel.recognizeImage(TFLiteObjectDetectionAPIModel.java:193)
at org.tensorflow.lite.examples.detection.DetectorActivity$2.run(DetectorActivity.java:183)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:175)
at android.os.HandlerThread.run(HandlerThread.java:65)
================================================== =======
更新:现在我们知道这是因为输入到模型的图像和模型的输入形状不匹配。通过Google Cloud Vision训练的模型的输入/输出形状似乎不一致。最近,我得到了[1 320 320 3]输入和[1 20 4]的一个,另一个[1 512 512 3]输入和[1 20 4]的了。
该演示应用程序可处理[1 300 300 3] in和[1 10 4] out的模型。
在使用Google Cloud Vision进行训练之前,如何分配模型的形状?如何使演示应用程序能够处理特定形状的模型?
================================================== =======
为了使演示应用程序能够处理特定形状的模型,我TF_OD_API_INPUT_SIZE
从300更改为320,这似乎已经解决了输入数据形状问题。但是,问题出在输出端。
新的错误日志显示: java.lang.IllegalArgumentException: Cannot copy between a TensorFlowLite tensor with shape [1, 20, 4] and a Java object with shape [1, 10, 4].
TEXT_SIZE_DIP
从10更改为20并没有帮助。
崩溃的原因是输入形状与模型的形状不匹配,在解决之后,由于输出形状的不匹配而导致了另一个崩溃。
解决方案是根据AutoML在Google Cloud上提供的模型元数据来调整演示应用程序的I / O形状。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句