hunglc007 / tensorflow-yolov4-tflite

YOLOv4, YOLOv4-tiny, YOLOv3, YOLOv3-tiny Implemented in Tensorflow 2.0, Android. Convert YOLO v4 .weights tensorflow, tensorrt and tflite
https://github.com/hunglc007/tensorflow-yolov4-tflite
MIT License
2.25k stars 1.24k forks source link

Yolo v4 Tiny In Android #113

Open iot-hunter opened 4 years ago

iot-hunter commented 4 years ago

I have Change ANCHORS MASKS OUTPUT_WIDTH to this:

    private static final int[] OUTPUT_WIDTH = new int[]{26, 13};
    private static final int[][] MASKS = new int[][]{{3, 4, 5}, {1, 2, 3}};
    private static final int[] ANCHORS = new int[]{
            10, 14, 23, 27, 37, 58, 81, 82, 135, 169, 344, 319
    };

but the predect Box is smaller or bigger than ground truth

hunglc007 commented 4 years ago

edit your anchors like this https://github.com/hunglc007/tensorflow-yolov4-tflite/issues/111#issuecomment-650205659

iot-hunter commented 4 years ago

@hunglc007 Do you means delete 10 from Anchors array ?

hunglc007 commented 4 years ago

You edit anchors into [23,27, 37,58, 81,82, 81,82, 135,169, 344,319]

iot-hunter commented 4 years ago

@hunglc007 mask change to new int[][]{{3, 4, 5}, {0, 1, 2}} ?

hattafudholi commented 4 years ago

Hi, it seems you guys are able to run the app without force closed. I had a problem in running the app, since it always force closed when starting the detection process (I guess). I got the following error from logcat in Android Studio

java.lang.IllegalArgumentException: Cannot copy between a TensorFlowLite tensor with shape [1, 2535, 4] and a Java object with shape [1, 26, 26, 3, 96].

Any thought is very appreciated. Cheers,

judahkshitij commented 4 years ago

Hi @hattafudholi I am seeing the same error when trying to run yolov4 tiny model in android app. Have you been able to resolve this error yet? Any help is greatly appreciated.

judahkshitij commented 4 years ago

When running larger (i.e., not tiny one) yolov4 model, I get the following error (as seen in logcat in Android Studio):

java.lang.IllegalArgumentException: Cannot copy from a TensorFlowLite tensor (Identity) with shape [1, 10647, 4] to a Java object with shape [1, 52, 52, 3, 85].

Any help or insight to resolve this error is greatly appreciated. Thanks.

hattafudholi commented 4 years ago

Hi @hattafudholi I am seeing the same error when trying to run yolov4 tiny model in android app. Have you been able to resolve this error yet? Any help is greatly appreciated.

no, not yet.

judahkshitij commented 4 years ago

Hi @hattafudholi I am seeing the same error when trying to run yolov4 tiny model in android app. Have you been able to resolve this error yet? Any help is greatly appreciated.

no, not yet.

oh ok. Thanks for the update. Not sure why its coming, could it be due to incorrect use of masks and anchors in the code?

judahkshitij commented 4 years ago

Hi @hattafudholi I am seeing the same error when trying to run yolov4 tiny model in android app. Have you been able to resolve this error yet? Any help is greatly appreciated.

no, not yet.

But for yolov4 tiny, i did change masks and anchors as described by @hunglc007 in one of the comments above. But I still see the above error. Sigh!

Suraj520 commented 4 years ago

@hunglc007 I am facing the same error while trying to run a yolov4.tflite, Please resolve

    java.lang.IllegalArgumentException: Cannot copy between a TensorFlowLite tensor with shape [1, 2535, 4] and a Java object with shape [1, 52, 52, 3, 85].
Abdktefane commented 4 years ago

same error any one can help ? Cannot copy between a TensorFlowLite tensor with shape [1, 10647, 4] and a Java object with shape [1, 52, 52, 3, 85]

WinstonHuTiger commented 4 years ago

I think I might just fix this problem by re-implementing the recongizeImage method in YoloV4Classifier class. This problem has nothing to do with anchor boxes or masks used, since the yolov4-tiny handle output bounding boxes is a little different from regular version. It just the output tensor's dimension and desired tensor's dimension cannot be matched. Therefore, we would see the error like this java.lang.IllegalArgumentException: Cannot copy between a TensorFlowLite tensor with shape [1, 2535, 4] and a Java object with shape [1, 52, 52, 3, 85] Hope it can be a little help for you.

hattafudholi commented 4 years ago

I think I might just fix this problem by re-implementing the recongizeImage method in YoloV4Classifier class. This problem has nothing to do with anchor boxes or masks used, since the yolov4-tiny handle output bounding boxes is a little different from regular version. It just the output tensor's dimension and desired tensor's dimension cannot be matched. Therefore, we would see the error like this java.lang.IllegalArgumentException: Cannot copy between a TensorFlowLite tensor with shape [1, 2535, 4] and a Java object with shape [1, 52, 52, 3, 85] Hope it can be a little help for you.

Hi, thanks for your excellent work @WinstonHuTiger . I came to your github and tried your version of android repo. It works well with your supplied model (yolov4-416-fp32.tflite). However, when I tried to change the model with other yolov4-tiny model (which I exported using convert_tflite.py from your repo and the public coco yolov4-tiny.weight), I always got the following error:

java.lang.IllegalArgumentException: Cannot copy between a TensorFlowLite tensor with shape [1, 2535, 80] and a Java object with shape [1, 2535, 4]

Do you have any clue? Cheers,