YOLOv5🚀 reproduction by Guo Quanhao using PaddlePaddle

Overview

YOLOv5-Paddle

YOLOv5 🚀 reproduction by Guo Quanhao using PaddlePaddle

Readme Card

  • 支持AutoBatch
  • 支持AutoAnchor
  • 支持GPU Memory

快速开始

使用AIStudio高性能环境快速构建YOLOv5训练(PaddlePaddle2.2.0-gpu version)

需要安装额外模块

pip install gputil==1.4.0
pip install pycocotools
COCO数据集

数据集已挂载至aistudio项目中,如果需要本地训练可以从这里下载数据集,和标签文件

Data
|-- coco
|   |-- annotions
|   |-- images
|      |-- train2017
|      |-- val2017
|      |-- test2017
|   |-- labels
|      |-- train2017
|      |-- val2017
|      |-- train2017.cache(初始解压可删除,训练时会自动生成)
|      |-- val2017.cache(初始解压可删除,训练时会自动生成)
|   |-- test-dev2017.txt
|   |-- val2017.txt
|   |-- train2017.txt
`   `-- validation

修改data/coco.yaml配置自己的coco路径,你可能需要修改path变量

path: /home/aistudio/Data/coco  # dataset root dir

训练

  • 考虑到AIStudio对于github的访问速度,预先提供了Arial.ttf

  • AIStudio后端不支持绘图,部分可视乎在AIStudio仓库被注释

training scratch for coco

mkdir /home/aistudio/.config/QuanhaoGuo/
cp /home/aistudio/Arial.ttf /home/aistudio/.config/QuanhaoGuo/
cd YOLOv5-Paddle
python train.py --img 896 --batch 8 --epochs 300 --data ./data/coco.yaml --cfg yolov5s.yaml --weights ''

验证

python val.py --img 640  --data ./data/coco.yaml --weights ./weights/yolov5s.pdparams --cfg yolov5s.yaml

通过--task [val/test]控制验证集和测试集

所有提供的模型验证精度如下,本仓库的所有资源文件包括预训练模型均可在百度云盘下载code:dng9

Model size
(pixels)
mAPval
0.5:0.95
mAPval
0.5
params
(M)
FLOPs
@640 (B)
mAPtest
0.5:0.95
mAPtest
0.5
YOLOv5n 640 28.4 46.5 1.9 4.5 28.1 46.2
YOLOv5s 640 37.2 56.4 7.2 16.5 37.1 56.1
YOLOv5m 640 45.1 64.2 21.2 49.0 45.4 64.3
YOLOv5l 640 48.6 67.4 46.5 109.1 48.9 67.5
YOLOv5x 640 50.6 69.1 86.7 205.7 0.507 0.690
YOLOv5n6 1280 34.0 51.1 3.2 4.6 34.3 51.7
YOLOv5s6 1280 44.5 63.4 16.8 12.6 44.3 63.0
YOLOv5m6 1280 50.9 69.4 35.7 50.0 51.1 69.5
YOLOv5l6 1280 53.5 71.8 76.8 111.4 53.7 71.8
YOLOv5x6
+ [TTA][TTA]
1280
1536
54.6
55.2
72.6
73.0
140.7
-
209.8
-
55.0
55.8
73.0
73.5

使用本地环境快速构建YOLOv5训练(PaddlePaddle2.2.0-gpu version)

git clone https://github.com/GuoQuanhao/YOLOv5-Paddle

然后按照使用AIStudio高性能环境快速构建YOLOv5训练执行

训练Custom Data

这里以一个类别的光栅数据集为例,数据集已上传至AIStudio

其组织结构如下:

Data
|-- guangshan
|   |-- images
|      |-- train
|      |-- val
|   |-- labels
|      |-- train
|      |-- val
|   |-- val.txt
|   |-- train.txt

另外你需要构建data/guangshan.yaml,相关文件已放入相关目录,主要用于指定数据集读取路径和模型配置。

# YOLOv5 reproduction 🚀 by GuoQuanhao

train: /home/aistudio/guangshan/images/train  # 118287 images
val: /home/aistudio/guangshan/images/val  # 5000 images
# number of classes
nc: 1
# class names
names: ['spectrum']

训练

python train.py --img 640 --batch 16 --epochs 100 --data ./data/guangshan.yaml --cfg yolov5s.yaml --weights ./weights/yolov5s.pdparams
Starting training for 100 epochs...

     Epoch   gpu_mem       box       obj       cls    labels  img_size
      0/99     4.19G    0.1039   0.04733         0        29       640: 100%|████████████████████████████████████████████████████████████████████| 9/9 [01:43<00:00, 11.50s/it]
               Class     Images     Labels          P          R     [email protected] [email protected]:.95: 100%|████████████████████████████████████████████████████| 1/1 [00:06<00:00,  6.64s/it]
                 all         16         29      0.266      0.379      0.226     0.0468

     Epoch   gpu_mem       box       obj       cls    labels  img_size
      1/99     4.41G   0.08177    0.0289         0        37       640: 100%|████████████████████████████████████████████████████████████████████| 9/9 [01:40<00:00, 11.20s/it]
               Class     Images     Labels          P          R     [email protected] [email protected]:.95: 100%|████████████████████████████████████████████████████| 1/1 [00:05<00:00,  5.49s/it]
                 all         16         29      0.462      0.445      0.398      0.109
......

完整的训练日志存在data/training.txt

利用VisualDL可视化训练过程

visualdl --logdir ./runs/train/exp

验证

python val.py --img 640  --data ./data/guangshan.yaml --cfg yolov5s.yaml --weights ./runs/train/exp/weights/best.pdparams

推理

python detect.py --weights ./runs/train/exp/weights/best.pdparams --cfg yolov5s.yaml --data ./data/guangshan.yaml --source ./data/images/guangshan.jpg

TODO

  • Multi-GPU Training ☘️
  • PaddleLite inference 🌟
  • Model to ONNX

关于作者

姓名 郭权浩
学校 电子科技大学研2020级
研究方向 计算机视觉
主页 Deep Hao的主页
github Deep Hao的github
如有错误,请及时留言纠正,非常蟹蟹!
后续会有更多论文复现系列推出,欢迎大家有问题留言交流学习,共同进步成长!
You might also like...
Torchserve server using a YoloV5 model running on docker with GPU and static batch inference to perform production ready inference.
Torchserve server using a YoloV5 model running on docker with GPU and static batch inference to perform production ready inference.

Yolov5 running on TorchServe (GPU compatible) ! This is a dockerfile to run TorchServe for Yolo v5 object detection model. (TorchServe (PyTorch librar

Drone detection using YOLOv5
Drone detection using YOLOv5

This drone detection system uses YOLOv5 which is a family of object detection architectures and we have trained the model on Drone Dataset. Overview I

Add gui for YoloV5 using PyQt5
Add gui for YoloV5 using PyQt5

HEAD 更新2021.08.16 **添加图片和视频保存功能: 1.图片和视频按照当前系统时间进行命名 2.各自检测结果存放入output文件夹 3.摄像头检测的默认设备序号更改为0,减少调试报错 温馨提示: 1.项目放置在全英文路径下,防止项目报错 2.默认使用cpu进行检测,自

A program to recognize fruits on pictures or videos using yolov5
A program to recognize fruits on pictures or videos using yolov5

Yolov5 Fruits Detector Requirements Either Linux or Windows. We recommend Linux for better performance. Python 3.6+ and PyTorch 1.7+. Installation To

Various operations like path tracking, counting, etc by using yolov5

Object-tracing-with-YOLOv5 Various operations like path tracking, counting, etc by using yolov5

FaceAnon - Anonymize people in images and videos using yolov5-crowdhuman
FaceAnon - Anonymize people in images and videos using yolov5-crowdhuman

Face Anonymizer Blur faces from image and video files in /input/ folder. Require

Yolov5-opencv-cpp-python - Example of using ultralytics YOLO V5 with OpenCV 4.5.4, C++ and Python
Yolov5-opencv-cpp-python - Example of using ultralytics YOLO V5 with OpenCV 4.5.4, C++ and Python

yolov5-opencv-cpp-python Example of performing inference with ultralytics YOLO V

Object detection and instance segmentation toolkit based on PaddlePaddle.
Object detection and instance segmentation toolkit based on PaddlePaddle.

Object detection and instance segmentation toolkit based on PaddlePaddle.

A PaddlePaddle version image model zoo.

Paddle-Image-Models English | 简体中文 A PaddlePaddle version image model zoo. Install Package Install by pip: $ pip install ppim Install by wheel package

Comments
  • train相关问题

    train相关问题

    作者您好,我在使用您的数据集训练YOLOv5n模型时,出现一个警告: Epoch gpu_mem box obj cls labels img_size 1/99 1.94G 0.09787 0.5162 0 679 640: 100%|███████████████████████████████████████████████████████████████████████| 57/57 [04:48<00:00, 5.05s/it] Class Images Labels P R [email protected] [email protected]:.95: 25%|██████████████▎ | 1/4 [00:17<00:53, 17.96s/it]/mnt/YOLOv5-Paddle-main/utils/loss.py:191: RuntimeWarning: divide by zero encountered in true_divide j = np.maximum(r, 1 / r).max(2) < self.hyp['anchor_t'] # compare Class Images Labels P R [email protected] [email protected]:.95: 100%|█████████████████████████████████████████████████████████| 4/4 [00:50<00:00, 12.56s/it] all 50 7742 0.571 0.664 0.579 0.188

    训练集为450,验证集为50,训练的目标只有一类“钢筋” (label: rebar) 想问一下会影响后续的部署使用吗?

    opened by qiujianchen 0
  • resume掉精度问题该怎么解决呢?

    resume掉精度问题该怎么解决呢?

    您好,我在使用您的代码时发现--resume时精度会下降,并且可能需要训练一些epoch才能恢复到之前的精度,请问该如何做才能做到resume时不掉精度呢(因为AIstudio的GPU每天只有8点算力卡,我所使用的数据集训练一个epoch需要一个小时,只能通过resume来完成整个训练过程) image

    图中的第一个39-45是直接resume的结果

    图中的第二个39-48是我认为之前训练时x['learning_rate']和x['momentum']存在,所以尝试在训练开始前给它们赋上warmup结束时的值,但发现效果并未达到预期 for j, x in enumerate(optimizer._param_groups): x['learning_rate'] = np.interp(nw, [0, nw], [hyp['warmup_bias_lr'] if j == 2 else 0.0, scheduler.base_lr * lf(epoch)]) if 'momentum' in x: x['momentum'] = np.interp(nw, [0, nw], [hyp['warmup_momentum'], hyp['momentum']])

    希望能得到您的帮助,谢谢!

    opened by diaoa1900 0
  • ai studio绘图问题

    ai studio绘图问题

    对比了yolov5的源码,绘图部分应该不是ai studio不支持的原因,而是在metrics.py的plot_pr_curve(px, py, ap, save_dir='pr_curve.png', names=())函数中,for i, y in enumerate(py.t())编写错误,修改为for i, y in enumerate(py.T)后可以正确绘制PR图

    opened by misaka-network10032 0
Owner
QuanHao Guo
Master at UESTC
QuanHao Guo
YOLOX-Paddle - A reproduction of YOLOX by PaddlePaddle

YOLOX-Paddle A reproduction of YOLOX by PaddlePaddle 数据集准备 下载COCO数据集,准备为如下路径 /ho

QuanHao Guo 6 Dec 18, 2022
[ICLR 2021] "CPT: Efficient Deep Neural Network Training via Cyclic Precision" by Yonggan Fu, Han Guo, Meng Li, Xin Yang, Yining Ding, Vikas Chandra, Yingyan Lin

CPT: Efficient Deep Neural Network Training via Cyclic Precision Yonggan Fu, Han Guo, Meng Li, Xin Yang, Yining Ding, Vikas Chandra, Yingyan Lin Accep

null 26 Oct 25, 2022
🍅🍅🍅YOLOv5-Lite: lighter, faster and easier to deploy. Evolved from yolov5 and the size of model is only 1.7M (int8) and 3.3M (fp16). It can reach 10+ FPS on the Raspberry Pi 4B when the input size is 320×320~

YOLOv5-Lite:lighter, faster and easier to deploy Perform a series of ablation experiments on yolov5 to make it lighter (smaller Flops, lower memory, a

pogg 1.5k Jan 5, 2023
TPH-YOLOv5: Improved YOLOv5 Based on Transformer Prediction Head for Object Detection on Drone-Captured Scenarios

TPH-YOLOv5 This repo is the implementation of "TPH-YOLOv5: Improved YOLOv5 Based on Transformer Prediction Head for Object Detection on Drone-Captured

cv516Buaa 439 Dec 22, 2022
Multi-task yolov5 with detection and segmentation based on yolov5

YOLOv5DS Multi-task yolov5 with detection and segmentation based on yolov5(branch v6.0) decoupled head anchor free segmentation head README中文 Ablation

null 150 Dec 30, 2022
Yolov5-lite - Minimal PyTorch implementation of YOLOv5

Yolov5-Lite: Minimal YOLOv5 + Deep Sort Overview This repo is a shortened versio

Kadir Nar 57 Nov 28, 2022
Mae segmentation - Reproduction of semantic segmentation using masked autoencoder (mae)

ADE20k Semantic segmentation with MAE Getting started Install the mmsegmentation

null 97 Dec 17, 2022
A pytorch reproduction of { Co-occurrence Feature Learning from Skeleton Data for Action Recognition and Detection with Hierarchical Aggregation }.

A PyTorch Reproduction of HCN Co-occurrence Feature Learning from Skeleton Data for Action Recognition and Detection with Hierarchical Aggregation. Ch

Guyue Hu 210 Dec 31, 2022
Reproduction process of AlexNet

PaddlePaddle论文复现杂谈 背景 注:该repo基于PaddlePaddle,对AlexNet进行复现。时间仓促,难免有所疏漏,如果问题或者想法,欢迎随时提issue一块交流。 飞桨论文复现赛地址:https://aistudio.baidu.com/aistudio/competitio

null 19 Nov 29, 2022
Remote sensing change detection using PaddlePaddle

Change Detection Laboratory Developing and benchmarking deep learning-based remo

Lin Manhui 15 Sep 23, 2022