Skip to content

YOLOv4, YOLOv4-tiny, YOLOv3, YOLOv3-tiny Implemented in Tensorflow 2.3.1, Android. Convert YOLO v4 .weights tensorflow, tensorrt and tflite

License

Notifications You must be signed in to change notification settings

nagi1995/tensorflow-yolov4-tflite

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Convert Darknet YOLOv4 or YOLOv3 to TensorFlow Model

license

YOLOv4, YOLOv4-tiny Implemented in Tensorflow 2.3.

This repository shows how to convert YOLO v4, YOLOv3, YOLO tiny .weights to .pb, .tflite and trt format for tensorflow, tensorflow lite, tensorRT.

  1. Setting Up Environment
  2. Convert YOLOv4 to TensorFlow
  3. Convert YOLOv4 to tflite

Setting Up Environment

Using Conda

CPU

# CPU
conda env create -f conda-cpu.yml


# activate environment on Windows or Linux
conda activate tf-cpu

# activate environment on Mac
source activate tf-cpu

GPU

# GPU
conda env create -f conda-gpu.yml

# activate environment on Windows or Linux
conda activate tf-gpu

# activate environment on Mac
source activate tf-gpu

Using Pip

# CPU
pip install -r requirements.txt

# GPU
pip install -r requirements-gpu.txt

Note: If installing GPU version with Pip, you need to install CUDA and cuDNN in your system. You can find the tutorial for Windows here.

Performance

Convert YOLOv4 to TensorFlow

# Convert darknet weights to tensorflow
## yolov4
python save_model.py --weights ./data/path/to/weights/file --output ./checkpoints/save/folder/name --input_size 416 --model yolov4 

## yolov4-tiny
python save_model.py --weights ./data/path/to/tiny/weights/file --output ./checkpoints/save/folder/name --input_size 416 --model yolov4 --tiny

If you want to run yolov3 or yolov3-tiny change --model yolov3 in command and also download corresponding YOLOv3 weights and and change --weights to ./data/yolov3.weights

Run Object Detection

# Run yolov4 on image
python detect-tiles.py

Output

Yolov4 original weight

Convert to tflite

# Save tf model for tflite converting
python save_model.py --weights ./data/path/to/weights/file --output ./checkpoints/yolov4-416 --input_size 416 --model yolov4 --framework tflite

# yolov4
python convert_tflite.py --weights ./checkpoints/save/folder/name --output ./checkpoints/save/folder/name/*.tflite

# yolov4 quantize float16
python convert_tflite.py --weights ./checkpoints/save/folder/name --output ./checkpoints/save/folder/name/*.tflite --quantize_mode float16

# yolov4 quantize int8
python convert_tflite.py --weights ./checkpoints/save/folder/name --output ./checkpoints/save/folder/name/*.tflite --quantize_mode int8

Run Objection Detection using TFLite Model

# Run demo tflite model
python detect-tiles-lite.py 
Yolov4 tflite fp16 weight

People who don't want to compromise their data can download this repo and create a virtual environment shown above and run

python gui.py

Demo video of GUI

output1_RJK7FOIC.mp4

Demo video of local cloud deployment

output1_6rJJLbFE.mp4

References

  • YOLOv4: Optimal Speed and Accuracy of Object Detection YOLOv4.
  • darknet

About

YOLOv4, YOLOv4-tiny, YOLOv3, YOLOv3-tiny Implemented in Tensorflow 2.3.1, Android. Convert YOLO v4 .weights tensorflow, tensorrt and tflite

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 59.0%
  • Java 40.3%
  • Other 0.7%