经过了一两天的折腾,我终于可以运行TensorFlowLite这个项目了,但是运行时,APP又闪退了,而且报了这个错误:
The model is not a valid Flatbuffer buffer
我使用的是这个教程:
https://www.jianshu.com/p/50f5c7d32575
完整报错信息如下所示:
I/tensorflow: CameraConnectionFragment: Desired size: 640x480, min size: 480x480
CameraConnectionFragment: Valid preview sizes: [640x480, 1280x720, 1280x960]
CameraConnectionFragment: Rejected preview sizes: [352x288, 320x240, 176x144]
CameraConnectionFragment: Exact size match found.
W/Gralloc4: allocator 3.x is not supported
I/OpenGLRenderer: Davey! duration=729ms; Flags=0, IntendedVsync=19184231315234, Vsync=19184631315218, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=19184633402720, AnimationStart=19184633419620, PerformTraversalsStart=19184633445520, DrawStart=19184635850020, SyncQueued=19184636460520, SyncStart=19184636978920, IssueDrawCommandsStart=19184637139320, SwapBuffers=19184638083420, FrameCompleted=19184961823020, DequeueBufferDuration=32864300, QueueBufferDuration=887800, GpuCompleted=8245932998015870825,
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: org.tensorflow.lite.examples.detection, PID: 15312
java.lang.AssertionError: Error occurred when initializing ObjectDetector: The model is not a valid Flatbuffer buffer
at org.tensorflow.lite.task.vision.detector.ObjectDetector.initJniWithByteBuffer(Native Method)
at org.tensorflow.lite.task.vision.detector.ObjectDetector.access$100(ObjectDetector.java:86)
at org.tensorflow.lite.task.vision.detector.ObjectDetector$3.createHandle(ObjectDetector.java:211)
at org.tensorflow.lite.task.core.TaskJniUtils.createHandleFromLibrary(TaskJniUtils.java:91)
at org.tensorflow.lite.task.vision.detector.ObjectDetector.createFromBufferAndOptions(ObjectDetector.java:207)
at org.tensorflow.lite.examples.detection.tflite.TFLiteObjectDetectionAPIModel.<init>(TFLiteObjectDetectionAPIModel.java:87)
at org.tensorflow.lite.examples.detection.tflite.TFLiteObjectDetectionAPIModel.create(TFLiteObjectDetectionAPIModel.java:81)
at org.tensorflow.lite.examples.detection.DetectorActivity.onPreviewSizeChosen(DetectorActivity.java:99)
at org.tensorflow.lite.examples.detection.CameraActivity.onPreviewFrame(CameraActivity.java:200)
at android.hardware.Camera$EventHandler.handleMessage(Camera.java:1227)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
I/Process: Sending signal. PID: 15312 SIG: 9
报错图片:
Logcat报错图片:
我使用的模型文件是自动下载的.tflite文件:
不知道这个问题应该怎么解决,希望有解决这个问题的同学可以和我分享一下解决方案,谢谢啦。