README.md 4.14 KB
Newer Older
dcuai's avatar
dcuai committed
1
# yolov5
dengjb's avatar
dengjb committed
2

dlyrm's avatar
dlyrm committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
## 论文

无论文

## 模型结构

YOLOv5 是一种目标检测算法,采用单阶段(one-stage)的方法,基于轻量级的卷积神经网络结构,通过引入不同尺度的特征融合和特征金字塔结构来实现高效准确的目标检测。

![Backbone.png](asserts%2FBackbone.png)

## 算法原理

YOLOv5 是一种基于单阶段目标检测算法,通过将图像划分为不同大小的网格,预测每个网格中的目标类别和边界框,利用特征金字塔结构和自适应的模型缩放来实现高效准确的实时目标检测。

![Algorithm_principle.png](asserts%2FAlgorithm_principle.png)

## 环境配置

### Docker (方法一)

```
dcuai's avatar
dcuai committed
24
docker pull image.sourcefind.cn:5000/dcu/admin/base/paddlepaddle:2.6.1-ubuntu22.04-dtk24.04.2-py3.10
dlyrm's avatar
dlyrm committed
25

dcuai's avatar
dcuai committed
26
docker run -it -v /path/your_code_data/:/path/your_code_data/ -v /opt/hyhal:/opt/hyhal --shm-size=32G --privileged=true --device=/dev/kfd --device=/dev/dri/ --group-add video --name docker_name imageID bash
dlyrm's avatar
dlyrm committed
27
28
29

cd /path/workspace/
pip3 install -r requirements.txt
dcuai's avatar
dcuai committed
30
pip3 insatll pillow==9.5.0
dlyrm's avatar
dlyrm committed
31
32
33
34
35
36
37
38
```

### Dockerfile (方法二)

```
cd ./docker
docker build --no-cache -t yolov5_paddle:last .
docker run -it -v /path/your_code_data/:/path/your_code_data/ --shm-size=32G --privileged=true --device=/dev/kfd --device=/dev/dri/ --group-add video --name docker_name imageID bash
dcuai's avatar
dcuai committed
39
pip3 insatll pillow==9.5.0
dlyrm's avatar
dlyrm committed
40
41
42
43
```

### Anaconda (方法三)

chenzk's avatar
chenzk committed
44
1、关于本项目DCU显卡所需的特殊深度学习库可从光合开发者社区下载安装: https://developer.sourcefind.cn/tool/
dlyrm's avatar
dlyrm committed
45
46

```
dcuai's avatar
dcuai committed
47
48
49
DTK软件栈:dtk24.04.2
python:python3.10
paddle:2.6.1
dlyrm's avatar
dlyrm committed
50
51
52
53
54
55
56
57
```

Tips:以上dtk软件栈、python、paddle等DCU相关工具版本需要严格一一对应

2、其他非特殊库直接按照requirements.txt安装

```
pip3 install -r requirements.txt
dcuai's avatar
dcuai committed
58
pip3 insatll pillow==9.5.0
dlyrm's avatar
dlyrm committed
59
60
61
62
63
64
```



## 数据集

dengjb's avatar
dengjb committed
65
66
67
68
69
70
在本测试中可以使用COCO2017数据集。
- 官方下载地址
  - [训练数据](http://images.cocodataset.org/zips/train2017.zip)
  - [验证数据](http://images.cocodataset.org/zips/val2017.zip)
  - [测试数据](http://images.cocodataset.org/zips/test2017.zip)
  - [标签数据](https://github.com/ultralytics/yolov5/releases/download/v1.0/coco2017labels.zip)
dlyrm's avatar
dlyrm committed
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92

数据集的目录结构如下:

```
├── images 
│   ├── train2017
│   ├── val2017
│   ├── test2017
├── labels
│   ├── train2017
│   ├── val2017
├── annotations
│   ├── instances_val2017.json
├── LICENSE
├── README.txt 
├── test-dev2017.txt
├── train2017.txt
├── val2017.txt

```

## 训练
dcuai's avatar
dcuai committed
93
- 训练数据集路径在 configs/dataset/coco_detection.yml中修改dataset_dir路径
dengjf's avatar
dengjf committed
94
- {config}参数使用时应改为配置文件地址:  configs/yolov5/yolov5_s_300e_coco.yml [该参数可替换为其他的参数文件地址]
dlyrm's avatar
dlyrm committed
95
96
97
98
99
### 单机单卡

```
export HIP_VISIBLE_DEVICES=0
export USE_MIOPEN_BATCHNORM=1
dengjf's avatar
dengjf committed
100
python -m paddle.distributed.launch  tools/train.py -c {config} --amp --eval
dlyrm's avatar
dlyrm committed
101
102
103
104
105
```

### 单机多卡

```
dengjb's avatar
dengjb committed
106
#以单机八卡为例子
dlyrm's avatar
dlyrm committed
107
108
109
export HIP_VISIBLE_DEVICES=0,1,2,3,4,5,6,7
export HSA_FORCE_FINE_GRAIN_PCIE=1
export USE_MIOPEN_BATCHNORM=1
dcuai's avatar
dcuai committed
110
python -m paddle.distributed.launch  tools/train.py -c {config} --amp --eval
dlyrm's avatar
dlyrm committed
111
112
113
114
115
116
117
118
119
120
121
```

## 推理

#### 单卡推理

```
HIP_VISIBLE_DEVICES=0 python tools/infer.py -c configs/yolov5/yolov5_s_300e_coco.yml -o weights=https://paddledet.bj.bcebos.com/models/yolov5_s_300e_coco.pdparams --infer_img=demo/000000014439_640x640.jpg
```
## result
此处以yolov5s模型进行推理测试
dengjb's avatar
dengjb committed
122
123
124
- 官方下载地址:
  - [yolov5_s_300e_coco.pdparams](https://paddledet.bj.bcebos.com/models/yolov5_s_300e_coco.pdparams)

dlyrm's avatar
dlyrm committed
125
![result_000000014439_640x640.jpg](asserts%2Fresult_000000014439_640x640.jpg)
dengjf's avatar
dengjf committed
126
### 精度
dlyrm's avatar
dlyrm committed
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142

|   模型    | 数据类型 | map0.5:0.95 | map0.5 |
|:-------:|:----:|:-----------:|:------:|
| yolov5s |  单精  |    37.0     |  56.4  |
| yolov5s |  混精  |    37.2     |  56.4  |


## 应用场景
### 算法分类
目标检测

### 热点应用行业
金融,交通,教育

## 源码仓库及问题反馈

chenzk's avatar
chenzk committed
143
https://developer.sourcefind.cn/codes/modelzoo/yolov5_paddle
dlyrm's avatar
dlyrm committed
144

dcuai's avatar
dcuai committed
145
## 参考资料
dlyrm's avatar
dlyrm committed
146

dengjb's avatar
dengjb committed
147
[GitHub - Paddle_yolo](https://github.com/PaddlePaddle/PaddleYOLO)