README.md 3.75 KB
Newer Older
Your Name's avatar
Your Name committed
1
2
# YoloV5

liucong's avatar
liucong committed
3
## 论文
Your Name's avatar
Your Name committed
4

liucong's avatar
liucong committed
5

Your Name's avatar
Your Name committed
6
7
8

## 模型结构

liucong's avatar
liucong committed
9
10
11
12
13
14
YoloV5是一种单阶段目标检测算法,该算法在YOLOV4的基础上添加了一些新的改进思路,使其速度与精度都得到了极大的性能提升。

<img src=./Doc/YOLOV5_01.jpg style="zoom:100%;" align=middle>

## 算法原理

Your Name's avatar
Your Name committed
15
YoloV5模型的主要改进思路有以下几点:
Your Name's avatar
Your Name committed
16
17
18
19
20
21

- 输入端的Mosaic数据增强、自适应锚框计算、自适应图像缩放操作;
- 主干网络的Focus结构与CSP结构;
- Neck端的FPN+PAN结构;
- 输出端的损失函数GIOU_Loss以及预测框筛选的DIOU_nms。

liucong's avatar
liucong committed
22
## 环境配置
liucong's avatar
liucong committed
23

liucong's avatar
liucong committed
24
25
26
27
28
拉取镜像:

```plaintext
docker pull image.sourcefind.cn:5000/dcu/admin/base/migraphx:4.0.0-centos7.6-dtk23.04.1-py38-latest
```
liucong's avatar
liucong committed
29

liucong's avatar
liucong committed
30
创建并启动容器:
Your Name's avatar
Your Name committed
31

liucong's avatar
liucong committed
32
33
```plaintext
docker run --shm-size 16g --network=host --name=yolov5_migraphx --privileged --device=/dev/kfd --device=/dev/dri --group-add video --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -v $PWD/yolov5_migraphx:/home/yolov5_migraphx -it <Your Image ID> /bin/bash
Your Name's avatar
Your Name committed
34

liucong's avatar
liucong committed
35
36
# 激活dtk
source /opt/dtk/env.sh
Your Name's avatar
Your Name committed
37
```
Your Name's avatar
Your Name committed
38

liucong's avatar
liucong committed
39
40
41
42
43
44
45
46
47
48
49
## 数据集

根据提供的样本数据,进行目标检测。

## 推理

### Python版本推理

下面介绍如何运行Python代码示例,Python示例的详细说明见Doc目录下的Tutorial_Python.md。

#### 设置环境变量
liucong's avatar
liucong committed
50

shizhm's avatar
shizhm committed
51
52
53
54
```
export PYTHONPATH=/opt/dtk/lib:$PYTHONPATH
```

liucong's avatar
liucong committed
55
#### 安装依赖
liucong's avatar
liucong committed
56
57
58

```
# 进入python示例目录
shizhm's avatar
shizhm committed
59
cd <path_to_yolov5_migraphx>/Python
liucong's avatar
liucong committed
60
61

# 安装依赖
liucong's avatar
liucong committed
62
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
shizhm's avatar
shizhm committed
63
```
liucong's avatar
liucong committed
64

liucong's avatar
liucong committed
65
#### 运行示例
shizhm's avatar
shizhm committed
66

shizhm's avatar
shizhm committed
67
68
69
70
71
72
73
74
75
76
77
78
79
YoloV5模型的推理示例程序是YoloV5_infer_migraphx.py,使用如下命令运行该推理示例:

```
# 进入python目录
cd <path_to_yolov5_migraphx>

# 进入Python目录
cd Python/
```

1. 静态推理

```
shizhm's avatar
shizhm committed
80
python YoloV5_infer_migraphx.py --staticInfer
shizhm's avatar
shizhm committed
81
82
83
```

2. 动态推理
shizhm's avatar
shizhm committed
84
85

```
shizhm's avatar
shizhm committed
86
python YoloV5_infer_migraphx.py --dynamicInfer
liucong's avatar
liucong committed
87
88
```

liucong's avatar
liucong committed
89
### C++版本推理
liucong's avatar
liucong committed
90

shizhm's avatar
shizhm committed
91
下面介绍如何运行C++代码示例,C++示例的详细说明见Doc目录下的Tutorial_Cpp.md。
liucong's avatar
liucong committed
92

Your Name's avatar
Your Name committed
93

liucong's avatar
liucong committed
94
#### 构建工程
Your Name's avatar
Your Name committed
95

Your Name's avatar
Your Name committed
96
```
Your Name's avatar
Your Name committed
97
98
99
rbuild build -d depend
```

liucong's avatar
liucong committed
100
#### 设置环境变量
Your Name's avatar
Your Name committed
101

Your Name's avatar
Your Name committed
102
103
将依赖库依赖加入环境变量LD_LIBRARY_PATH,在~/.bashrc中添加如下语句:

Your Name's avatar
Your Name committed
104
```
shizhm's avatar
shizhm committed
105
export LD_LIBRARY_PATH=<path_to_yolov5_migraphx>/depend/lib64/:$LD_LIBRARY_PATH
Your Name's avatar
Your Name committed
106
107
108
109
110
111
112
113
```

然后执行:

```
source ~/.bashrc
```

liucong's avatar
liucong committed
114
#### 运行示例
Your Name's avatar
Your Name committed
115

shizhm's avatar
shizhm committed
116
YoloV5示例程序编译成功后,执行如下指令运行该示例:
Your Name's avatar
Your Name committed
117
118

```
shizhm's avatar
shizhm committed
119
# 进入yolov5 migraphx工程根目录
shizhm's avatar
shizhm committed
120
cd <path_to_yolov5_migraphx>
Your Name's avatar
Your Name committed
121

liucong's avatar
liucong committed
122
# 进入build目录
shizhm's avatar
shizhm committed
123
124
125
126
127
128
129
130
cd build/
```

1. 静态推理

```
./YOLOV5 0
```
Your Name's avatar
Your Name committed
131

shizhm's avatar
shizhm committed
132
133
134
135
2. 动态推理

```
./YOLOV5 1
Your Name's avatar
Your Name committed
136
```
Your Name's avatar
Your Name committed
137

liucong's avatar
liucong committed
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
## result

### Python版本

静态推理:

python程序运行结束后,会在当前目录生成YOLOV5静态推理检测结果可视化图像。

<img src="./Resource/Images/Result.jpg" alt="Result" style="zoom: 50%;" />

动态推理:

python程序运行结束后,会在当前目录生成YoloV5动态推理检测结果可视化图像。

<img src="./Resource/Images/Result0.jpg" alt="Result_2" style="zoom: 50%;" />

<img src="./Resource/Images/Result1.jpg" alt="Result1" style="zoom: 50%;" />

### C++版本

静态推理:

C++程序运行结束后,会在build目录生成YOLOV5静态推理检测结果可视化图像。

<img src="./Resource/Images/Result.jpg" alt="Result" style="zoom:50%;" />

动态推理:

C++程序运行结束后,会在build目录生成YoloV5动态shape推理检测结果可视化图像。
167
168

<img src="./Resource/Images/Result0.jpg" alt="Result" style="zoom:50%;" />
Your Name's avatar
Your Name committed
169

170
<img src="./Resource/Images/Result1.jpg" alt="Result" style="zoom:50%;" />
Your Name's avatar
Your Name committed
171

liucong's avatar
liucong committed
172
173
174
175
176
177
178
179
180
181
## 应用场景

### 算法类别

`目标检测`

### 热点应用行业

`交通`,`教育`,`化工`

shizhm's avatar
shizhm committed
182
## 源码仓库及问题反馈
Your Name's avatar
Your Name committed
183

liucong's avatar
liucong committed
184
https://developer.hpccube.com/codes/modelzoo/yolov5_migraphx
Your Name's avatar
Your Name committed
185
186
187

## 参考

liucong's avatar
liucong committed
188
https://github.com/ultralytics/yolov5