# tensorflow-yolov4-tflite
[![license](https://img.shields.io/github/license/mashape/apistatus.svg)](LICENSE)
YOLOv4, YOLOv4-tiny Implemented in Tensorflow 2.0.
Convert YOLO v4, YOLOv3, YOLO tiny .weights to .pb, .tflite and trt format for tensorflow, tensorflow lite, tensorRT.
Download yolov4.weights file: https://drive.google.com/open?id=1cewMfusmPjYWbrnuJRuKhPMwRe_b9PaT
### Prerequisites
* Tensorflow 2.3.0rc0
### Performance
<p align="center"><img src="data/performance.png" width="640"\></p>
### Demo
```bash
# Convert darknet weights to tensorflow
## yolov4
python save_model.py --weights ./data/yolov4.weights --output ./checkpoints/yolov4-416 --input_size 416 --model yolov4
## yolov4-tiny
python save_model.py --weights ./data/yolov4-tiny.weights --output ./checkpoints/yolov4-tiny-416 --input_size 416 --model yolov4 --tiny
# Run demo tensorflow
python detect.py --weights ./checkpoints/yolov4-416 --size 416 --model yolov4 --image ./data/kite.jpg
python detect.py --weights ./checkpoints/yolov4-tiny-416 --size 416 --model yolov4 --image ./data/kite.jpg --tiny
```
If you want to run yolov3 or yolov3-tiny change ``--model yolov3`` in command
#### Output
##### Yolov4 original weight
<p align="center"><img src="result.png" width="640"\></p>
##### Yolov4 tflite int8
<p align="center"><img src="result-int8.png" width="640"\></p>
### Convert to tflite
```bash
# Save tf model for tflite converting
python save_model.py --weights ./data/yolov4.weights --output ./checkpoints/yolov4-416 --input_size 416 --model yolov4 --framework tflite
# yolov4
python convert_tflite.py --weights ./checkpoints/yolov4-416 --output ./checkpoints/yolov4-416.tflite
# yolov4 quantize float16
python convert_tflite.py --weights ./checkpoints/yolov4-416 --output ./checkpoints/yolov4-416-fp16.tflite --quantize_mode float16
# yolov4 quantize int8
python convert_tflite.py --weights ./checkpoints/yolov4-416 --output ./checkpoints/yolov4-416-int8.tflite --quantize_mode int8 --dataset ./coco_dataset/coco/val207.txt
# Run demo tflite model
python detect.py --weights ./checkpoints/yolov4-416.tflite --size 416 --model yolov4 --image ./data/kite.jpg --framework tflite
```
Yolov4 and Yolov4-tiny int8 quantization have some issues. I will try to fix that. You can try Yolov3 and Yolov3-tiny int8 quantization
### Convert to TensorRT
```bash# yolov3
python save_model.py --weights ./data/yolov3.weights --output ./checkpoints/yolov3.tf --input_size 416 --model yolov3
python convert_trt.py --weights ./checkpoints/yolov3.tf --quantize_mode float16 --output ./checkpoints/yolov3-trt-fp16-416
# yolov3-tiny
python save_model.py --weights ./data/yolov3-tiny.weights --output ./checkpoints/yolov3-tiny.tf --input_size 416 --tiny
python convert_trt.py --weights ./checkpoints/yolov3-tiny.tf --quantize_mode float16 --output ./checkpoints/yolov3-tiny-trt-fp16-416
# yolov4
python save_model.py --weights ./data/yolov4.weights --output ./checkpoints/yolov4.tf --input_size 416 --model yolov4
python convert_trt.py --weights ./checkpoints/yolov4.tf --quantize_mode float16 --output ./checkpoints/yolov4-trt-fp16-416
```
### Evaluate on COCO 2017 Dataset
```bash
# run script in /script/get_coco_dataset_2017.sh to download COCO 2017 Dataset
# preprocess coco dataset
cd data
mkdir dataset
cd ..
cd scripts
python coco_convert.py --input ./coco/annotations/instances_val2017.json --output val2017.pkl
python coco_annotation.py --coco_path ./coco
cd ..
# evaluate yolov4 model
python evaluate.py --weights ./data/yolov4.weights
cd mAP/extra
python remove_space.py
cd ..
python main.py --output results_yolov4_tf
```
#### mAP50 on COCO 2017 Dataset
| Detection | 512x512 | 416x416 | 320x320 |
|-------------|---------|---------|---------|
| YoloV3 | 55.43 | 52.32 | |
| YoloV4 | 61.96 | 57.33 | |
### Benchmark
```bash
python benchmarks.py --size 416 --model yolov4 --weights ./data/yolov4.weights
```
#### TensorRT performance
| YoloV4 416 images/s | FP32 | FP16 | INT8 |
|---------------------|----------|----------|----------|
| Batch size 1 | 55 | 116 | |
| Batch size 8 | 70 | 152 | |
#### Tesla P100
| Detection | 512x512 | 416x416 | 320x320 |
|-------------|---------|---------|---------|
| YoloV3 FPS | 40.6 | 49.4 | 61.3 |
| YoloV4 FPS | 33.4 | 41.7 | 50.0 |
#### Tesla K80
| Detection | 512x512 | 416x416 | 320x320 |
|-------------|---------|---------|---------|
| YoloV3 FPS | 10.8 | 12.9 | 17.6 |
| YoloV4 FPS | 9.6 | 11.7 | 16.0 |
#### Tesla T4
| Detection | 512x512 | 416x416 | 320x320 |
|-------------|---------|---------|---------|
| YoloV3 FPS | 27.6 | 32.3 | 45.1 |
| YoloV4 FPS | 24.0 | 30.3 | 40.1 |
#### Tesla P4
| Detection | 512x512 | 416x416 | 320x320 |
|-------------|---------|---------|---------|
| YoloV3 FPS | 20.2 | 24.2 | 31.2 |
| YoloV4 FPS | 16.2 | 20.2 | 26.5 |
#### Macbook Pro 15 (2.3GHz i7)
| Detection | 512x512 | 416x416 | 320x320 |
|-------------|---------|---------|---------|
| YoloV3 FPS | | | |
| YoloV4 FPS | | | |
### Traning your own model
```bash
# Prepare your dataset
# If you want to train from scratch:
In config.py set FISRT_STAGE_EPOCHS=0
# Run script:
python train.py
# Transfer learning:
python train.py --weights ./data/yolov4.weights
```
The training performance is not fully reproduced yet, so I recommended to use Alex's [Darknet](https://github.com/AlexeyAB/darknet) to train your own data, then convert the .weights to tensorflow or tflite.
### TODO
* [x] Convert YOLOv4 to TensorRT
* [x] YOLOv4 tflite on android
* [ ] YOLOv4 tflite on ios
* [x] Training code
* [x] Update scale xy
* [ ] ciou
* [ ] Mosaic data augmentation
* [x] Mish activation
* [x] yolov4 tflite version
* [x] yolov4 in8 tflite version for mobile
### References
* YOLOv4: Optimal Speed and Accuracy of Object Detection [YOLOv4](https://arxiv.org/abs/2004.10934).
* [darknet](https://github.com/AlexeyAB/darknet)
My project is inspired by these previous fantastic YOLOv3 implementations:
* [Yolov3 tensorflow](https://github.com/YunYang1994/tensorflow-yolov3)
* [Yolov3 tf2](https://github.com/zzh8829/yolov3-tf2)
没有合适的资源?快使用搜索试试~ 我知道了~
yolov4-tflite将 YOLO v4、YOLOv3、YOLO tiny .weights 转换为 .pb、.tflite
共126个文件
png:26个
py:23个
xml:18个
2 下载量 5 浏览量
2023-08-16
11:15:10
上传
评论
收藏 34.07MB ZIP 举报
温馨提示
YOLOv4、YOLOv4-tiny 在 Tensorflow 2.0 中实现。将 YOLO v4、YOLOv3、YOLO tiny .weights 转换为 .pb、.tflite 和 trt 格式,以用于tensorflow、tensorflow lite、tensorRT。 演示代码: # Convert darknet weights to tensorflow ## yolov4 python save_model.py --weights ./data/yolov4.weights --output ./checkpoints/yolov4-416 --input_size 416 --model yolov4 ## yolov4-tiny python save_model.py --weights ./data/yolov4-tiny.weights --output ./checkpoints/yolov4-tiny-416 --input_size 416 --model yolov4 --tiny # Run demo tensorflow python d
资源推荐
资源详情
资源评论
收起资源包目录
yolov4-tflite将 YOLO v4、YOLOv3、YOLO tiny .weights 转换为 .pb、.tflite (126个子文件)
gradlew.bat 2KB
.gitignore 156B
.gitignore 14B
build.gradle 2KB
download_model.gradle 642B
build.gradle 640B
settings.gradle 35B
gradlew 5KB
gradle-wrapper.jar 53KB
YoloV4Classifier.java 25KB
CameraConnectionFragment.java 21KB
CameraActivity.java 17KB
DetectorActivity.java 10KB
MultiBoxTracker.java 8KB
ImageUtils.java 7KB
Utils.java 7KB
LegacyCameraConnectionFragment.java 7KB
DetectorTest.java 6KB
Logger.java 6KB
MainActivity.java 6KB
BorderedText.java 4KB
Size.java 4KB
Classifier.java 4KB
AutoFitTextureView.java 3KB
RecognitionScoreView.java 2KB
OverlayView.java 2KB
ResultsView.java 923B
kite.jpg 1.35MB
kite.jpg 1.35MB
kite.jpg 1.35MB
sample_image.jpg 522KB
table.jpg 25KB
chair.jpg 21KB
caret.jpg 10KB
LICENSE 1KB
README.md 6KB
CODE_OF_CONDUCT.md 3KB
README.md 709B
road.mp4 782KB
coco.names 627B
voc.names 134B
yymnist.names 20B
result-int8.png 1.79MB
result.png 1.79MB
girl.png 649KB
performance.png 147KB
ic_launcher_round.png 13KB
tfl2_logo.png 12KB
ic_launcher_round.png 9KB
ic_launcher_foreground.png 6KB
ic_launcher.png 6KB
tfl2_logo_dark.png 5KB
ic_launcher_round.png 5KB
ic_launcher_foreground.png 5KB
ic_launcher.png 4KB
ic_launcher_foreground.png 4KB
ic_launcher_round.png 4KB
ic_launcher.png 3KB
ic_launcher_foreground.png 3KB
ic_launcher.png 2KB
ic_launcher_round.png 2KB
ic_launcher.png 2KB
ic_launcher_foreground.png 2KB
ic_launcher.png 1KB
ic_launcher.png 1KB
ic_launcher.png 929B
icn_chevron_down.png 597B
icn_chevron_up.png 596B
proguard-rules.pro 751B
gradle.properties 779B
gradle-wrapper.properties 232B
main.py 27KB
yolov4.py 16KB
dataset.py 14KB
utils.py 12KB
backbone.py 8KB
train.py 7KB
evaluate.py 6KB
benchmarks.py 6KB
detectvideo.py 5KB
convert_trt.py 4KB
detect.py 4KB
coco_convert.py 3KB
remove_space.py 3KB
coco_annotation.py 3KB
voc_convert.py 3KB
convert_tflite.py 3KB
common.py 3KB
voc_annotation.py 3KB
save_model.py 3KB
intersect-gt-and-pred.py 2KB
config.py 2KB
google_utils.py 2KB
voc_make_names.py 1KB
get_coco_dataset_2017.sh 940B
get_voc2012.sh 514B
yolov4-416-fp32.tflite 23.16MB
val2014.txt 8.28MB
val2017.txt 997KB
labelmap.txt 665B
共 126 条
- 1
- 2
资源评论
paterWang
- 粉丝: 1061
- 资源: 1206
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功