README.md 4.68 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
30
31
32

```shell
docker pull image.sourcefind.cn:5000/dcu/admin/base/migraphx:4.0.0-centos7.6-dtk23.04.1-py38-latest
```

yaoht's avatar
yaoht committed
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
创建并启动容器:

```shell
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 $PWD/yolov8_migraphx:/home/yolov8_migraphx -it <Your Image ID> /bin/bash

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

### Dockerfile(方法二)

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

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 $PWD/yolov8_migraphx:/home/yolov8_migraphx -it <Your Image ID> /bin/bash

# 激活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
99
100
101

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


yaoht's avatar
yaoht committed
102
#### 构建工程
yaoht's avatar
yaoht committed
103
104
105
106
107

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

yaoht's avatar
yaoht committed
108
#### 设置环境变量
yaoht's avatar
yaoht committed
109
110
111
112
113
114
115
116
117
118
119
120
121

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

```shell
export LD_LIBRARY_PATH=<path_to_yolov8_migraphx>/depend/lib64/:$LD_LIBRARY_PATH
```

然后执行:

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

yaoht's avatar
yaoht committed
122
#### 运行示例
yaoht's avatar
yaoht committed
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145

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
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程序运行结束后,会在当前目录生成YOLOV8静态推理检测结果可视化图像。

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

动态推理:

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

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

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

### C++版本

静态推理:

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

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

动态推理:

C++程序运行结束后,会在build目录生成YoloV8动态shape推理检测结果可视化图像。
yaoht's avatar
yaoht committed
175
176
177
178
179

<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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
### 精度



## 应用场景

### 算法类别

`目标检测`

### 热点应用行业

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

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

yaoht's avatar
yaoht committed
196
https://developer.hpccube.com/codes/modelzoo/yolov8_migraphx
yaoht's avatar
yaoht committed
197

yaoht's avatar
yaoht committed
198
## 参考资料
yaoht's avatar
yaoht committed
199

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