README.md 4.14 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>

## 算法原理

liucong's avatar
liucong committed
15
YOLOv5算法通过将图像划分为不同大小的网格,预测每个网格中的目标类别和边界框,利用特征金字塔结构和自适应的模型缩放来实现高效准确的实时目标检测。
Your Name's avatar
Your Name committed
16

liucong's avatar
liucong committed
17
<img src=./Doc/YOLOV5_02.png style="zoom:100%;" align=middle>
Your Name's avatar
Your Name committed
18

liucong's avatar
liucong committed
19
## 环境配置
liucong's avatar
liucong committed
20

liucong's avatar
liucong committed
21
22
### Docker(方法一)

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

```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
28

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

liucong's avatar
liucong committed
31
32
```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
33

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

liucong's avatar
liucong committed
38
39
40
41
42
43
44
45
46
### Dockerfile(方法二)

```
cd ./docker
docker build --no-cache -t yolov5_migraphx:2.0 .

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
```

liucong's avatar
liucong committed
47
48
49
50
51
52
53
54
55
56
57
## 数据集

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

## 推理

### Python版本推理

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

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

shizhm's avatar
shizhm committed
59
60
61
62
```
export PYTHONPATH=/opt/dtk/lib:$PYTHONPATH
```

liucong's avatar
liucong committed
63
#### 安装依赖
liucong's avatar
liucong committed
64
65
66

```
# 进入python示例目录
shizhm's avatar
shizhm committed
67
cd <path_to_yolov5_migraphx>/Python
liucong's avatar
liucong committed
68
69

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

liucong's avatar
liucong committed
73
#### 运行示例
shizhm's avatar
shizhm committed
74

shizhm's avatar
shizhm committed
75
76
77
78
79
80
81
82
83
84
85
86
87
YoloV5模型的推理示例程序是YoloV5_infer_migraphx.py,使用如下命令运行该推理示例:

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

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

1. 静态推理

```
shizhm's avatar
shizhm committed
88
python YoloV5_infer_migraphx.py --staticInfer
shizhm's avatar
shizhm committed
89
90
91
```

2. 动态推理
shizhm's avatar
shizhm committed
92
93

```
shizhm's avatar
shizhm committed
94
python YoloV5_infer_migraphx.py --dynamicInfer
liucong's avatar
liucong committed
95
96
```

liucong's avatar
liucong committed
97
### C++版本推理
liucong's avatar
liucong committed
98

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

Your Name's avatar
Your Name committed
101

liucong's avatar
liucong committed
102
#### 构建工程
Your Name's avatar
Your Name committed
103

Your Name's avatar
Your Name committed
104
```
Your Name's avatar
Your Name committed
105
106
107
rbuild build -d depend
```

liucong's avatar
liucong committed
108
#### 设置环境变量
Your Name's avatar
Your Name committed
109

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

Your Name's avatar
Your Name committed
112
```
shizhm's avatar
shizhm committed
113
export LD_LIBRARY_PATH=<path_to_yolov5_migraphx>/depend/lib64/:$LD_LIBRARY_PATH
Your Name's avatar
Your Name committed
114
115
116
117
118
119
120
121
```

然后执行:

```
source ~/.bashrc
```

liucong's avatar
liucong committed
122
#### 运行示例
Your Name's avatar
Your Name committed
123

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

```
shizhm's avatar
shizhm committed
127
# 进入yolov5 migraphx工程根目录
shizhm's avatar
shizhm committed
128
cd <path_to_yolov5_migraphx>
Your Name's avatar
Your Name committed
129

liucong's avatar
liucong committed
130
# 进入build目录
shizhm's avatar
shizhm committed
131
132
133
134
135
136
137
138
cd build/
```

1. 静态推理

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

shizhm's avatar
shizhm committed
140
141
142
143
2. 动态推理

```
./YOLOV5 1
Your Name's avatar
Your Name committed
144
```
Your Name's avatar
Your Name committed
145

liucong's avatar
liucong committed
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
## 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推理检测结果可视化图像。
175
176

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

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

liucong's avatar
liucong committed
180
181
182
183
### 精度



liucong's avatar
liucong committed
184
185
186
187
188
189
190
191
192
193
## 应用场景

### 算法类别

`目标检测`

### 热点应用行业

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

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

liucong's avatar
liucong committed
196
https://developer.hpccube.com/codes/modelzoo/yolov5_migraphx
Your Name's avatar
Your Name committed
197

liucong's avatar
liucong committed
198
## 参考资料
Your Name's avatar
Your Name committed
199

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