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.23k stars 1.24k forks source link

How to convert custom yolov4 model to tensorflow? #209

Open saikrishnadas opened 4 years ago

saikrishnadas commented 4 years ago

I trained a custom yolov4 using darknet with 24 classes. Now how do i convert it to tensorflow and what all files should i change in order to do custom model conversion?? @hunglc007

Thanks in advance, SAI

hadizand commented 3 years ago

Below is all you need to do --python save_model.py --weights ./checkpoints/yolov4 --output ./checkpoints/yolov4-416 --input_size 416--model yolov4

This will generate the saved model.

KYUNGGUK-CHOI commented 3 years ago

Dear @hadizand , Thanks for the reply but I think that comments work only in case of demo?

@saikrishnadas is the same with you that getting result of 2 files('model.index', 'model.data-00000-of-00001' after running custom model?

hadizand commented 3 years ago

Dear @hadizand , Thanks for the reply but I think that comments work only in case of demo?

It also works for custom model if checkpoints folder contains the trained custom weights. For example, I used below command and it generated the saved model (I set the input size of 512, and it only contained 2 classes) python save_model.py --weights ./checkpoints/yolov4 --output ./checkpoints/yolov4-512 --input_size 512 --model yolov4

If someone wanted to deploy over android, it is necessary to set the tflite framework flag as follow flags.DEFINE_string('framework', 'tflite', 'define what framework do you want to convert (tf, trt, tflite)')

After doing so, convert_tflite.py could generate the custom tflite model for me. I deployed the custom tflite model over android device and it works fine.

vandics commented 3 years ago

I got an error when converting saved model to tflite like CUDA_ERROR_UNKNOWN: unknown error then Fatal Python error: Aborted. Did you get this error too?

hadizand commented 3 years ago

I got an error when converting saved model to tflite like CUDA_ERROR_UNKNOWN: unknown error then Fatal Python error: Aborted. Did you get this error too?

I did not get that error. Probably you did some part of training on a device with GPU, and the rest on another device with CPU. Check if you are doing all process in the same device.

vandics commented 3 years ago

I have done with that error by upgrading my TensorFlow to 2.6. But when I downgrade TensorFlow to 2.4, that error show again. I use TensorFlow CPU

Aparajit-Garg commented 2 years ago

Hi, Thank you for a great repository. I am trying to execute the save_model.py file to generate tensorflow model and then converting it to tflite model using convert_tflite.py, all the programs execute successfully but the tflite model is of 245 Mb in space, which does not seem right. Can anyone please help out?

Command for pb conversion: python save_model.py --weights ./data/yolov4.weights --output ./checkpoints/yolov4-416 --input_size 416 --model yolov4 --framework tflite

Command for tflite conversion: python convert_tflite.py --weights ./checkpoints/yolov4-416 --output ./checkpoints/yolov4-416.tflite

Python version: 3.7.0 Tensorflow version: 2.3.1 (CPU) System: i5 11th gen Windows 10 CPU Thank you.