当前位置: 首页 > 软件库 > 手机/移动开发 > >

tensorflow-yolov4-tflite

授权协议 MIT License
开发语言 Java
所属分类 手机/移动开发
软件类型 开源软件
地区 不详
投 递 者 年光明
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

tensorflow-yolov4-tflite

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

Demo

# 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

Yolov4 tflite int8

Convert to tflite

# 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

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

# 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

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

# 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 to train your own data, then convert the .weights to tensorflow or tflite.

TODO

  • Convert YOLOv4 to TensorRT
  • YOLOv4 tflite on android
  • YOLOv4 tflite on ios
  • Training code
  • Update scale xy
  • ciou
  • Mosaic data augmentation
  • Mish activation
  • yolov4 tflite version
  • yolov4 in8 tflite version for mobile

References

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

My project is inspired by these previous fantastic YOLOv3 implementations:

  • Yolo V7 是 YOLO 系列中最新的物体检测器。它在精度和速度方面都是目前最先进的物体检测器。它的硬件效率非常高,可以在迁移学习的帮助下在小型数据集上进行训练。除了对象检测之外,YOLO v7 还能够执行某些其他任务,例如分割和姿势估计。拥有一个准确且高效的模型固然好,但它只有在可以部署到生产环境中才有用。在 YOLO v7 的官方 repo 中,其作者已经创建了将 YOLO v7 转换为

  • 一、相关环境介绍 1、网络训练的环境 tensorflow-gpu==1.4.0 Keras==2.1.5 python==3.6.2 2、h5->pb->tflite的环境 tensorflow==2.2.0 python==3.6.2 二、转换过程 1、加载h5权重,并转换为pb 修改yolov4网络结构中keras的导包命令,tensorflow=2.2.0中自带的有keras # 将所有的

  • domino 惯用选项 在Android上使用数据很不方便! (Working with data on Android is inconvenient!) If you’ve used TensorFlow Lite on Android before, chances are that you’ve had to deal with the tedious task of pre-proces

  • Unfortunately you can't convert the complete YOLOv3 model to a tensorflow lite model at the moment. This is because YOLOv3 extends on the original darknet backend used by YOLO and YOLOv2 by introducin

  • 原工程为 https://github.com/hunglc007/tensorflow-yolov4-tflite 不过我运行时发现一个bug,就是在OpenCV画框时,浮点型会报错,所以就修复了一下,工程为:https://github.com/moneypi/tensorflow-yolov4-tflite   要注意的几点,一个是该工程是建议使用 Tensorflow 2.3,确实如此,如

 相关资料
  • Introduction TensorFlow™ is an open source software library for numerical computation using data flow graphs. Nodes in the graph represent mathematical operations, while the graph edges represent the

  • Tensorflow 是谷歌在 2015 年 11 月开源的机器学习框架,来源于 Google 内部的深度学习框架 DistBelief。由于其良好的架构、分布式架构支持以及简单易用,自开源以来得到广泛的关注。主要特点包括: 良好的架构,使用数据流图来进行数值计算 简单易用,并且社区还有很多的模型封装(比如 keras 和 skflow 等) 灵活高效,既可以使用 CPU,也可以使用 GPU 开放

  • TF install install cuda cuda 有很多版本,要仔细看清自己需要什么样的版本: TF cuda 版本对照 error import tensorflow出现:ImportError: libcublas.so.9.0: cannot open shared object file: No such file or directory 尝试使用下面方法解决: 在 PATH中

  • TensorFlow 是一个端到端开源机器学习平台。它拥有一个全面而灵活的生态系统,其中包含各种工具、库和社区资源,可助力研究人员推动先进机器学习技术的发展,并使开发者能够轻松地构建和部署由机器学习提供支持的应用。 轻松地构建模型 TensorFlow 提供多个抽象级别,因此您可以根据自己的需求选择合适的级别。您可以使用高阶 Keras API 构建和训练模型,该 API 让您能够轻松地开始使用

  • Keras是紧凑,易于学习的高级Python库,运行在TensorFlow框架之上。它的重点是理解深度学习技术,例如为神经网络创建维护形状和数学细节概念的层。freamework的创建可以是以下两种类型 - 顺序API 功能API 在Keras中创建深度学习模型有以下 8 个步骤 - 加载数据 预处理加载的数据 模型的定义 编译模型 指定模型 评估模型 进行必要的预测 保存模型 下面将使用Jupy

  • Welcome! Contents Introduction: Why debugging in TensorFlow is difficult Basic and advanced methods for debugging TensorFlow codes General tips and guidelines for easy-debuggable code Benchmarking and