README.md 3.41 KB
Newer Older
Your Name's avatar
Your Name committed
1
2
3
4
5
6
7
8
# YoloV5

## 模型介绍

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

## 模型结构

Your Name's avatar
Your Name committed
9
YoloV5模型的主要改进思路有以下几点:
Your Name's avatar
Your Name committed
10
11
12
13
14
15

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

shizhm's avatar
shizhm committed
16
## Python版本推理
liucong's avatar
liucong committed
17

shizhm's avatar
shizhm committed
18
下面介绍如何运行Python代码示例,Python示例的详细说明见Doc目录下的Tutorial_Python.md。
liucong's avatar
liucong committed
19

shizhm's avatar
shizhm committed
20
### 下载镜像
Your Name's avatar
Your Name committed
21
22

在光源可拉取推理的docker镜像,YoloV5工程推荐的镜像如下:
Your Name's avatar
Your Name committed
23

Your Name's avatar
Your Name committed
24
25
26
```python
docker pull image.sourcefind.cn:5000/dcu/admin/base/custom:ort1.14.0_migraphx3.0.0-dtk22.10.1
```
Your Name's avatar
Your Name committed
27

shizhm's avatar
shizhm committed
28
### 设置Python环境变量
liucong's avatar
liucong committed
29

shizhm's avatar
shizhm committed
30
31
32
33
34
```
export PYTHONPATH=/opt/dtk/lib:$PYTHONPATH
```

### 安装依赖
liucong's avatar
liucong committed
35
36
37

```
# 进入python示例目录
shizhm's avatar
shizhm committed
38
cd <path_to_yolov5_migraphx>/Python
liucong's avatar
liucong committed
39
40
41

# 安装依赖
pip install -r requirements.txt
shizhm's avatar
shizhm committed
42
```
liucong's avatar
liucong committed
43

shizhm's avatar
shizhm committed
44
### 运行示例
shizhm's avatar
shizhm committed
45

shizhm's avatar
shizhm committed
46
47
48
49
50
51
52
53
54
55
56
57
58
YoloV5模型的推理示例程序是YoloV5_infer_migraphx.py,使用如下命令运行该推理示例:

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

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

1. 静态推理

```
shizhm's avatar
shizhm committed
59
python YoloV5_infer_migraphx.py --staticInfer
shizhm's avatar
shizhm committed
60
61
62
63
64
65
66
```

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

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

2. 动态推理
shizhm's avatar
shizhm committed
67
68

```
69
70
71
72
# 开启环境变量
export MIGRAPHX_DYNAMIC_SHAPE=1

# 运行示例
shizhm's avatar
shizhm committed
73
python YoloV5_infer_migraphx.py --dynamicInfer
liucong's avatar
liucong committed
74
75
```

shizhm's avatar
shizhm committed
76
程序运行结束会在当前目录生成YoloV5动态推理检测结果可视化图像Result0.jpg、Result1.jpg。
liucong's avatar
liucong committed
77

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

<img src="./Resource/Images/Result1.jpg" alt="Result1" style="zoom: 50%;" />
liucong's avatar
liucong committed
81
82
83

## C++版本推理

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

shizhm's avatar
shizhm committed
86
87
88
89
90
91
92
### 下载镜像

在光源中下载MIGraphX镜像: 

```
docker pull image.sourcefind.cn:5000/dcu/admin/base/custom:ort1.14.0_migraphx3.0.0-dtk22.10.1
```
liucong's avatar
liucong committed
93

Your Name's avatar
Your Name committed
94

shizhm's avatar
shizhm committed
95
### 构建工程
Your Name's avatar
Your Name committed
96

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

### 设置环境变量
Your Name's avatar
Your Name committed
102

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

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

然后执行:

```
source ~/.bashrc
```

shizhm's avatar
shizhm committed
115
### 运行示例
Your Name's avatar
Your Name committed
116

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

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

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

1. 静态推理

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

shizhm's avatar
shizhm committed
133
134
135
136
137
138
139
程序运行结束后,会在当前目录生成YOLOV5静态推理检测结果可视化图像Result.jpg

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

2. 动态推理

```
140
141
142
# 开启环境变量
export MIGRAPHX_DYNAMIC_SHAPE=1

shizhm's avatar
shizhm committed
143
144
# 执行动态推理示例程序
./YOLOV5 1
Your Name's avatar
Your Name committed
145
```
Your Name's avatar
Your Name committed
146

shizhm's avatar
shizhm committed
147
程序运行结束会在build目录生成YoloV5动态shape推理检测结果可视化图像Result0.jpg、Result1.jpg。
148
149

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

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

shizhm's avatar
shizhm committed
153
## 源码仓库及问题反馈
Your Name's avatar
Your Name committed
154
155
156
157
158
159

​		https://developer.hpccube.com/codes/modelzoo/yolov5_migraphx

## 参考

​		https://github.com/ultralytics/yolov5