Background
I successfully converted my YOLOV5 model from YOLOV5.pt to YOLOV5-fp16.tflite and was able to run it on python(refer to the test video on Google Drive).
I used the conversion method python export.py --include tflite
.
Google Colab where the weights.pt
was trained on
I then used this and tried to port it to Android Studio(Artic Fox), loading the model to assets
, adjusted the modelPath
under PreviewImageActivity.java
. After this, the application is then exported into an APK.
Problem
When the application is executed it cannot get past the part after the video is processed into images for object detection and crashes.
I tried searching online for solutions and it did not help as my situation seems to be different. Any help would be good since I am doing this for my school project thanks!
Here is the zip to the application with the test video to process. The Username and Password is admin
and password
respectively.
Edit 1
Here is the log cat error when I run the program on my device(Samsung Tab A) via USB debugging.
2022-01-19 10:06:53.117 6044-6044/bline.detector.com.ffmpegvideoeditor D/PreviewImageAdapter: bitmap: [android.graphics.Bitmap@65ea227, android.graphics.Bitmap@8e60e7d, android.graphics.Bitmap@40939c3]
2022-01-19 10:06:53.148 6044-6044/bline.detector.com.ffmpegvideoeditor D/PreviewImageAdapter: bitmap: [android.graphics.Bitmap@65ea227, android.graphics.Bitmap@8e60e7d, android.graphics.Bitmap@40939c3, android.graphics.Bitmap@bca1579]
2022-01-19 10:06:53.180 6044-6044/bline.detector.com.ffmpegvideoeditor D/PreviewImageAdapter: bitmap: [android.graphics.Bitmap@65ea227, android.graphics.Bitmap@8e60e7d, android.graphics.Bitmap@40939c3, android.graphics.Bitmap@bca1579, android.graphics.Bitmap@33baf1f]
2022-01-19 10:06:53.210 6044-6044/bline.detector.com.ffmpegvideoeditor D/PreviewImageAdapter: bitmap: [android.graphics.Bitmap@65ea227, android.graphics.Bitmap@8e60e7d, android.graphics.Bitmap@40939c3, android.graphics.Bitmap@bca1579, android.graphics.Bitmap@33baf1f, android.graphics.Bitmap@e4d9035]
2022-01-19 10:06:53.423 6044-6044/bline.detector.com.ffmpegvideoeditor D/AndroidRuntime: Shutting down VM
2022-01-19 10:06:53.427 6044-6044/bline.detector.com.ffmpegvideoeditor E/AndroidRuntime: FATAL EXCEPTION: main
Process: bline.detector.com.ffmpegvideoeditor, PID: 6044
java.lang.RuntimeException: Unable to start activity ComponentInfo{bline.detector.com.ffmpegvideoeditor/bline.detector.com.ffmpegvideoeditor.activity.PreviewImageActivity}: java.lang.IllegalArgumentException: Cannot copy from a TensorFlowLite tensor (StatefulPartitionedCall:0) with shape [1, 6300, 6] to a Java object with shape [1, 10, 4].
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3623)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3775)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2261)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:8107)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
Caused by: java.lang.IllegalArgumentException: Cannot copy from a TensorFlowLite tensor (StatefulPartitionedCall:0) with shape [1, 6300, 6] to a Java object with shape [1, 10, 4].
at org.tensorflow.lite.Tensor.throwIfDstShapeIsIncompatible(Tensor.java:482)
at org.tensorflow.lite.Tensor.copyTo(Tensor.java:252)
at org.tensorflow.lite.NativeInterpreterWrapper.run(NativeInterpreterWrapper.java:175)
at org.tensorflow.lite.Interpreter.runForMultipleInputsOutputs(Interpreter.java:360)
at bline.detector.com.ffmpegvideoeditor.activity.objectDetectorClass.recognizeVideo(objectDetectorClass.java:118)
at bline.detector.com.ffmpegvideoeditor.activity.PreviewImageActivity.onCreate(PreviewImageActivity.java:118)
at android.app.Activity.performCreate(Activity.java:7957)
at android.app.Activity.performCreate(Activity.java:7946)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3598)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3775)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2261)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:8107)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100) ```