pytorch / android-demo-app

PyTorch android examples of usage in applications
1.47k stars 606 forks source link

[torchvideo] It has bug in torchvideo when "temporal > 4" #239

Open Le0v1n opened 2 years ago

Le0v1n commented 2 years ago

I modify COUNT_OF_FRAMES_PER_INFERENCE=4 -> 16 in Constants.javaand it has error when program running:

E/AndroidRuntime: FATAL EXCEPTION: ModuleActivity
    Process: org.pytorch.demo.torchvideo, PID: 6094
    java.lang.IllegalStateException: Buffer underflow

Specific in LiveVideoClassificationActivity.java:

TensorImageUtils.bitmapToFloatBuffer(centerCroppedBitmap,
                    0,
                    0,
                    Constants.TARGET_VIDEO_SIZE,
                    Constants.TARGET_VIDEO_SIZE,
                    Constants.MEAN_RGB,
                    Constants.STD_RGB,
                    inTensorBuffer,
                    (Constants.COUNT_OF_FRAMES_PER_INFERENCE - 1) * mFrameCount
                            * Constants.TARGET_VIDEO_SIZE * Constants.TARGET_VIDEO_SIZE);

mFrameCount in [0, 4] is normal, but it will have error when mFrameCount > 4.

MainActivity.javahas the same problem of Buffer underflow when COUNT_OF_FRAMES_PER_INFERENCE = 4 -> COUNT_OF_FRAMES_PER_INFERENCE > 4.

So How to solve this problem of Buffer underflow?

Thank you very much!