Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yolov4-tiny to tensorflow lite #413

Closed
abhi-84 opened this issue Dec 8, 2021 · 3 comments
Closed

yolov4-tiny to tensorflow lite #413

abhi-84 opened this issue Dec 8, 2021 · 3 comments

Comments

@abhi-84
Copy link

abhi-84 commented Dec 8, 2021

Hi all

Is it possible to convert yolov4-tiny model to tflite? With given instruction, yolov4-tiny can be converted to TensorFlow:

python save_model.py --weights ./data/yolov4-tiny.weights --output ./checkpoints/yolov4-tiny-416 --input_size 416 --model yolov4 --tiny

But when I am trying to convert it to tflite using the following, it throws an error!

python save_model.py --weights ./data/yolov4.weights --output ./checkpoints/yolov4-416 --input_size 416 --model yolov4 --framework tflite

Error:
File "save_model.py", line 49, in save_tf
utils.load_weights(model, FLAGS.weights, FLAGS.model, FLAGS.tiny)
File "/home/abhishek/Documents/tensorflow-yolov4-tflite-master/core/utils.py", line 63, in load_weights
conv_weights = conv_weights.reshape(conv_shape).transpose([2, 3, 1, 0])
ValueError: cannot reshape array of size 379318 into shape (256,256,3,3)

I am interested to reduce the size of yolo-tiny by converting it to tflite. Is that possible?

@abhi-84
Copy link
Author

abhi-84 commented Dec 9, 2021

I followed this #214 and it worked! I am ablr to convert ti int8 format and able able to detect my test image.

I was able to convert to int8 format smoothly using @murdockhou post but during the detection phase, I was faced a few issues! I am just listing them here with the solution with the hope it may help someone.

Take care of 3 things for successful conversion and detection:

  1. No change in core/config.py except this line. Here you update your class file name. In my case, it is "data.names" __C.YOLO.CLASSES = "./data/classes/data.names"

  2. After appending code in detect.py as mentioned in the post and using int8 optimized model version, it may throw an error about "decode not found". Thus in the header, include decode: "from core.yolov4 import decode"

  3. Add --tiny flag at end of detect command: "python detect.py --weights ./checkpoints/yolov4-tiny-416-int8.tflite --size 416 --model yolov4 --image ./data/test1.jpeg --framework tflite --tiny". Use your own test image!

@abhi-84 abhi-84 closed this as completed Dec 9, 2021
@abhi-84
Copy link
Author

abhi-84 commented Dec 16, 2021

2. appending code in detect.py as mentioned in th

In one more situation, this error might appear during save_model.py.
When one of thr options is either wrong or typo in "--" sign as "-" in the following command:
python save_model.py --weights ./data/yolov4-tiny-custom_final.weights --output ./checkpoints/yolov4-tiny --input_size 224 --model yolov4 --tiny

@KuoEuran
Copy link

@abhi-84 Hi, can you convert the yolov4-tiny with separable convolution layer in dakrnet? tks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants