README.md 5.26 KB
Newer Older
yaoht's avatar
yaoht committed
1
2
# YoloV8

yaoht's avatar
yaoht committed
3
## 论文
yaoht's avatar
yaoht committed
4

yaoht's avatar
yaoht committed
5

yaoht's avatar
yaoht committed
6
7
8

## 模型结构

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

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

## 算法原理
yaoht's avatar
yaoht committed
14

yaoht's avatar
yaoht committed
15
16
YOLOv8算法通过将图像划分为不同大小的网格,预测每个网格中的目标类别和边界框,利用特征金字塔结构和自适应的模型缩放来实现高效准确的实时目标检测。
- 骨干网络和 Neck 部分将 YOLOv5 的 C3 结构换成了梯度流更丰富的 C2f 结构,并对不同尺度模型调整了不同的通道数,大幅提升了模型性能。
yaoht's avatar
yaoht committed
17
18
19
20
- Head 部分相比 YOLOv5 改动较大,换成了目前主流的解耦头结构,将分类和检测头分离,同时也从 Anchor-Based 换成了 Anchor-Free.
- Loss 计算方面采用了 TaskAlignedAssigner 正样本分配策略,并引入了 Distribution Focal Loss.
- 训练的数据增强部分引入了 YOLOX 中的最后 10 epoch 关闭 Mosiac 增强的操作,可以有效地提升精度

yaoht's avatar
yaoht committed
21
<img src=./Doc/yolov8_model.jpg style="zoom:100%;" align=middle>
yaoht's avatar
yaoht committed
22

yaoht's avatar
yaoht committed
23
## 环境配置
yaoht's avatar
yaoht committed
24

yaoht's avatar
yaoht committed
25
### Docker(方法一)
yaoht's avatar
yaoht committed
26

yaoht's avatar
yaoht committed
27
拉取镜像:
yaoht's avatar
yaoht committed
28
29

```shell
yaoht's avatar
yaoht committed
30
docker pull image.sourcefind.cn:5000/dcu/admin/base/migraphx:4.3.0-ubuntu20.04-dtk24.04.1-py3.10
yaoht's avatar
yaoht committed
31
32
```

yaoht's avatar
yaoht committed
33
34
35
创建并启动容器:

```shell
yaoht's avatar
yaoht committed
36
docker run --shm-size 16g --network=host --name=yolov8_migraphx --privileged --device=/dev/kfd --device=/dev/dri --group-add video --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -v /opt/hyhal:/opt/hyhal:ro -v $PWD/yolov8_migraphx:/home/yolov8_migraphx -it <Your Image ID> /bin/bash
yaoht's avatar
yaoht committed
37
38
39
40
41
42
43
44
45
46
47

# 激活dtk
source /opt/dtk/env.sh
```

### Dockerfile(方法二)

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

yaoht's avatar
yaoht committed
48
docker run --shm-size 16g --network=host --name=yolov8_migraphx --privileged --device=/dev/kfd --device=/dev/dri --group-add video --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -v /opt/hyhal:/opt/hyhal:ro -v $PWD/yolov8_migraphx:/home/yolov8_migraphx -it <Your Image ID> /bin/bash
yaoht's avatar
yaoht committed
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64

# 激活dtk
source /opt/dtk/env.sh
```

## 数据集

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

## 推理

### Python版本推理

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

#### 设置环境变量
yaoht's avatar
yaoht committed
65
66
67
68
69

```shell
export PYTHONPATH=/opt/dtk/lib:$PYTHONPATH
```

yaoht's avatar
yaoht committed
70
#### 安装依赖
yaoht's avatar
yaoht committed
71
72
73
74
75
76

```shell
# 进入python示例目录
cd <path_to_yolov8_migraphx>/Python

# 安装依赖
yaoht's avatar
yaoht committed
77
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
yaoht's avatar
yaoht committed
78
79
```

yaoht's avatar
yaoht committed
80
#### 运行示例
yaoht's avatar
yaoht committed
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96

YoloV8模型的推理示例程序是YoloV8_infer_migraphx.py,使用如下命令运行该推理示例:


1. 静态推理

```shell
python YoloV8_infer_migraphx.py --staticInfer
```

2. 动态推理

```shell
python YoloV8_infer_migraphx.py --dynamicInfer
```

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

yaoht's avatar
yaoht committed
99
100
101
102
103
104
105
106
107
108
注意:当使用操作系统不一样时,CMakeList需要做相应的修改:

```
# ubuntu操作系统
${CMAKE_CURRENT_SOURCE_DIR}/depend/lib64/ 修改为 ${CMAKE_CURRENT_SOURCE_DIR}/depend/lib/

# centos操作系统
${CMAKE_CURRENT_SOURCE_DIR}/depend/lib/ 修改为 ${CMAKE_CURRENT_SOURCE_DIR}/depend/lib64/
```

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


yaoht's avatar
yaoht committed
112
#### 构建工程
yaoht's avatar
yaoht committed
113
114
115
116
117

```shell
rbuild build -d depend
```

yaoht's avatar
yaoht committed
118
#### 设置环境变量
yaoht's avatar
yaoht committed
119
120
121

将依赖库依赖加入环境变量LD_LIBRARY_PATH,在~/.bashrc中添加如下语句:

yaoht's avatar
yaoht committed
122
123
124
125
126
127
128
129
当操作系统是ubuntu系统时:

```shell
export LD_LIBRARY_PATH=<path_to_yolov9_migraphx>/depend/lib/:$LD_LIBRARY_PATH
```

当操作系统是centos系统时:

yaoht's avatar
yaoht committed
130
```shell
yaoht's avatar
yaoht committed
131
export LD_LIBRARY_PATH=<path_to_yolov9_migraphx>/depend/lib64/:$LD_LIBRARY_PATH
yaoht's avatar
yaoht committed
132
133
134
135
136
137
138
139
```

然后执行:

```shell
source ~/.bashrc
```

yaoht's avatar
yaoht committed
140
#### 运行示例
yaoht's avatar
yaoht committed
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163

YoloV8示例程序编译成功后,执行如下指令运行该示例:

```shell
# 进入yolov8 migraphx工程根目录
cd <path_to_yolov8_migraphx>

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

1. 静态推理

```shell
./YOLOV8 0
```

2. 动态推理

```shell
./YOLOV8 1
```

yaoht's avatar
yaoht committed
164
165
166
167
168
169
170
171
## result

### Python版本

静态推理:

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

yaoht's avatar
yaoht committed
172
<img src="./Resource/Images/Result_python.jpg" alt="Result" style="zoom: 50%;" />
yaoht's avatar
yaoht committed
173
174
175
176
177

动态推理:

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

yaoht's avatar
yaoht committed
178
<img src="./Resource/Images/Result0_python.jpg" alt="Result_2" style="zoom: 50%;" />
yaoht's avatar
yaoht committed
179

yaoht's avatar
yaoht committed
180
<img src="./Resource/Images/Result1_python.jpg" alt="Result1" style="zoom: 50%;" />
yaoht's avatar
yaoht committed
181
182
183
184
185
186
187
188
189
190
191
192

### C++版本

静态推理:

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

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

动态推理:

C++程序运行结束后,会在build目录生成YoloV8动态shape推理检测结果可视化图像。
yaoht's avatar
yaoht committed
193
194
195
196
197

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

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

yaoht's avatar
yaoht committed
198
199
200
201
202
203
204
205
206
207
208
209
210
211
### 精度



## 应用场景

### 算法类别

`目标检测`

### 热点应用行业

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

yaoht's avatar
yaoht committed
212
213
## 源码仓库及问题反馈

yaoht's avatar
yaoht committed
214
https://developer.hpccube.com/codes/modelzoo/yolov8_migraphx
yaoht's avatar
yaoht committed
215

yaoht's avatar
yaoht committed
216
## 参考资料
yaoht's avatar
yaoht committed
217

yaoht's avatar
yaoht committed
218
https://github.com/ultralytics/ultralytics