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
PyTorch implementation of Glow

glow-pytorch PyTorch implementation of Glow, Generative Flow with Invertible 1x1 Convolutions (https://arxiv.org/abs/1807.03039) Usage: python train.p

Kim Seonghyeon 433 Dec 27, 2022
Py4fi2nd - Jupyter Notebooks and code for Python for Finance (2nd ed., O'Reilly) by Yves Hilpisch.

Python for Finance (2nd ed., O'Reilly) This repository provides all Python codes and Jupyter Notebooks of the book Python for Finance -- Mastering Dat

Yves Hilpisch 1k Jan 05, 2023
DeepAL: Deep Active Learning in Python

DeepAL: Deep Active Learning in Python Python implementations of the following active learning algorithms: Random Sampling Least Confidence [1] Margin

Kuan-Hao Huang 583 Jan 03, 2023
FinGAT: A Financial Graph Attention Networkto Recommend Top-K Profitable Stocks

FinGAT: A Financial Graph Attention Networkto Recommend Top-K Profitable Stocks This is our implementation for the paper: FinGAT: A Financial Graph At

Yu-Che Tsai 64 Dec 13, 2022
PoolFormer: MetaFormer is Actually What You Need for Vision

PoolFormer: MetaFormer is Actually What You Need for Vision (arXiv) This is a PyTorch implementation of PoolFormer proposed by our paper "MetaFormer i

Sea AI Lab 1k Dec 30, 2022
Multiple Object Extraction from Aerial Imagery with Convolutional Neural Networks

This is an implementation of Volodymyr Mnih's dissertation methods on his Massachusetts road & building dataset and my original methods that are publi

Shunta Saito 255 Sep 07, 2022
Simple Dynamic Batching Inference

Simple Dynamic Batching Inference 解决了什么问题? 众所周知,Batch对于GPU上深度学习模型的运行效率影响很大。。。 是在Inference时。搜索、推荐等场景自带比较大的batch,问题不大。但更多场景面临的往往是稀碎的请求(比如图片服务里一次一张图)。 如果

116 Jan 01, 2023
Listing arxiv - Personalized list of today's articles from ArXiv

Personalized list of today's articles from ArXiv Print and/or send to your gmail

Lilianne Nakazono 5 Jun 17, 2022
Discovering Dynamic Salient Regions with Spatio-Temporal Graph Neural Networks

Discovering Dynamic Salient Regions with Spatio-Temporal Graph Neural Networks This is the official code for DyReg model inroduced in Discovering Dyna

Bitdefender Machine Learning 11 Nov 08, 2022
More Photos are All You Need: Semi-Supervised Learning for Fine-Grained Sketch Based Image Retrieval

More Photos are All You Need: Semi-Supervised Learning for Fine-Grained Sketch Based Image Retrieval, CVPR 2021. Ayan Kumar Bhunia, Pinaki nath Chowdh

Ayan Kumar Bhunia 22 Aug 27, 2022
CDTrans: Cross-domain Transformer for Unsupervised Domain Adaptation

[ICCV2021] TransReID: Transformer-based Object Re-Identification [pdf] The official repository for TransReID: Transformer-based Object Re-Identificati

DamoCV 569 Dec 30, 2022
Combining Diverse Feature Priors

Combining Diverse Feature Priors This repository contains code for reproducing the results of our paper. Paper: https://arxiv.org/abs/2110.08220 Blog

Madry Lab 5 Nov 12, 2022
Unofficial TensorFlow implementation of the Keyword Spotting Transformer model

Keyword Spotting Transformer This is the unofficial TensorFlow implementation of the Keyword Spotting Transformer model. This model is used to train o

Intelligent Machines Limited 8 May 11, 2022
An implementation of the Contrast Predictive Coding (CPC) method to train audio features in an unsupervised fashion.

CPC_audio This code implements the Contrast Predictive Coding algorithm on audio data, as described in the paper Unsupervised Pretraining Transfers we

Meta Research 283 Dec 30, 2022
Molecular Sets (MOSES): A Benchmarking Platform for Molecular Generation Models

Molecular Sets (MOSES): A benchmarking platform for molecular generation models Deep generative models are rapidly becoming popular for the discovery

MOSES 656 Dec 29, 2022
Binary Passage Retriever (BPR) - an efficient passage retriever for open-domain question answering

BPR Binary Passage Retriever (BPR) is an efficient neural retrieval model for open-domain question answering. BPR integrates a learning-to-hash techni

Studio Ousia 147 Dec 07, 2022
Depth-Aware Video Frame Interpolation (CVPR 2019)

DAIN (Depth-Aware Video Frame Interpolation) Project | Paper Wenbo Bao, Wei-Sheng Lai, Chao Ma, Xiaoyun Zhang, Zhiyong Gao, and Ming-Hsuan Yang IEEE C

Wenbo Bao 7.7k Dec 31, 2022
A commany has recently introduced a new type of bidding, the average bidding, as an alternative to the bid given to the current maximum bidding

Business Problem A commany has recently introduced a new type of bidding, the average bidding, as an alternative to the bid given to the current maxim

Kübra Bilinmiş 1 Jan 15, 2022
An implementation for the ICCV 2021 paper Deep Permutation Equivariant Structure from Motion.

Deep Permutation Equivariant Structure from Motion Paper | Poster This repository contains an implementation for the ICCV 2021 paper Deep Permutation

72 Dec 27, 2022
Official Implementation of "Third Time's the Charm? Image and Video Editing with StyleGAN3" https://arxiv.org/abs/2201.13433

Third Time's the Charm? Image and Video Editing with StyleGAN3 Yuval Alaluf*, Or Patashnik*, Zongze Wu, Asif Zamir, Eli Shechtman, Dani Lischinski, Da

531 Dec 20, 2022