README.md 4.34 KB
Newer Older
dcuai's avatar
dcuai committed
1
# YOLOv7
shizhm's avatar
shizhm committed
2

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

liucong's avatar
liucong committed
5
6
7
YOLOv7: Trainable bag-of-freebies sets new state-of-the-art for real-time object detectors

- https://arxiv.org/pdf/2207.02696.pdf
Your Name's avatar
Your Name committed
8
9
10

## 模型结构

liucong's avatar
liucong committed
11
YOLOV7是2022年最新出现的一种YOLO系列目标检测模型,该模型的网络结构包括三个部分:input、backbone和head。
liucong's avatar
liucong committed
12

liucong's avatar
liucong committed
13
<img src="./Doc/YoloV7_model.png" alt="YOLOV7_02" style="zoom:67%;" />
liucong's avatar
liucong committed
14
15
16

## 算法原理

liucong's avatar
liucong committed
17
18
19
YOLOv7的作者提出了 Extended-ELAN (E-ELAN)结构。E-ELAN采用了ELAN类似的特征聚合和特征转移流程,仅在计算模块中采用了类似ShuffleNet的分组卷积、扩张模块和混洗模块,最终通过聚合模块融合特征。通过采用这种方法可以获得更加多样的特征,同时提高参数的计算和利用效率。

<img src="./Doc/YoloV7_suanfa.png" alt="YOLOV7_suanfa" style="zoom:67%;" />
Your Name's avatar
Your Name committed
20

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

liucong's avatar
liucong committed
23
24
### Docker(方法一)

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

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

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

liucong's avatar
liucong committed
33
```plaintext
yaoht's avatar
yaoht committed
34
docker run --shm-size 16g --network=host --name=yolov7_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/yolov7_migraphx:/home/yolov7_migraphx -it <Your Image ID> /bin/bash
Your Name's avatar
Your Name committed
35

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

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

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

yaoht's avatar
yaoht committed
46
docker run --shm-size 16g --network=host --name=yolov7_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/yolov7_migraphx:/home/yolov7_migraphx -it <Your Image ID> /bin/bash
liucong's avatar
liucong committed
47
48
49

# 激活dtk
source /opt/dtk/env.sh
liucong's avatar
liucong committed
50
51
```

liucong's avatar
liucong committed
52
53
54
55
56
57
58
59
60
61
62
## 数据集

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

## 推理

### Python版本推理

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

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

shizhm's avatar
shizhm committed
64
65
66
67
```
export PYTHONPATH=/opt/dtk/lib:$PYTHONPATH
```

liucong's avatar
liucong committed
68
#### 安装依赖
liucong's avatar
liucong committed
69
70
71

```
# 进入python示例目录
shizhm's avatar
shizhm committed
72
cd <path_to_yolov7_migraphx>/Python
liucong's avatar
liucong committed
73
74

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

liucong's avatar
liucong committed
78
#### 运行示例
shizhm's avatar
shizhm committed
79
80

YoloV7模型的推理示例程序是YoloV7_infer_migraphx.py,在Python目录下使用如下命令运行该推理示例:
liucong's avatar
liucong committed
81

shizhm's avatar
shizhm committed
82
```
liucong's avatar
liucong committed
83
84
85
86
87
88
89
90
python YoloV7_infer_migraphx.py \
	--imgpath 测试图像路径 \ 
	--modelpath onnx模型路径 \
	--objectThreshold 判断是否有物体阈值,默认0.5 \
	--confThreshold 置信度阈值,默认0.25 \
	--nmsThreshold nms阈值,默认0.5 \
```

liucong's avatar
liucong committed
91
### C++版本推理
liucong's avatar
liucong committed
92

yaoht's avatar
yaoht committed
93
94
95
96
97
98
99
100
101
102
注意:当使用操作系统不一样时,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/
```

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

liucong's avatar
liucong committed
105

liucong's avatar
liucong committed
106
#### 构建工程
Your Name's avatar
Your Name committed
107

Your Name's avatar
Your Name committed
108
```
Your Name's avatar
Your Name committed
109
110
111
rbuild build -d depend
```

liucong's avatar
liucong committed
112
#### 设置环境变量
Your Name's avatar
Your Name committed
113

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

yaoht's avatar
yaoht committed
116
117
118
119
当操作系统是ubuntu系统时:

```shell
export LD_LIBRARY_PATH=<path_to_yolov9_migraphx>/depend/lib/:$LD_LIBRARY_PATH
Your Name's avatar
Your Name committed
120
```
yaoht's avatar
yaoht committed
121
122
123
124
125

当操作系统是centos系统时:

```shell
export LD_LIBRARY_PATH=<path_to_yolov9_migraphx>/depend/lib64/:$LD_LIBRARY_PATH
Your Name's avatar
Your Name committed
126
127
128
129
130
131
132
133
```

然后执行:

```
source ~/.bashrc
```

liucong's avatar
liucong committed
134
#### 运行示例
Your Name's avatar
Your Name committed
135

liucong's avatar
liucong committed
136
成功编译YoloV7工程后,执行如下命令运行该示例:
Your Name's avatar
Your Name committed
137
138

```
shizhm's avatar
shizhm committed
139
# 进入yolov7 migraphx工程根目录
shizhm's avatar
shizhm committed
140
cd <path_to_yolov7_migraphx> 
Your Name's avatar
Your Name committed
141

liucong's avatar
liucong committed
142
143
# 进入build目录
cd ./build/
Your Name's avatar
Your Name committed
144

liucong's avatar
liucong committed
145
# 执行示例程序
146
./YoloV7
Your Name's avatar
Your Name committed
147
```
Your Name's avatar
Your Name committed
148

liucong's avatar
liucong committed
149
150
151
152
153
154
155
156
157
158
159
## result

### Python版本

python程序运行结束后,会在当前目录生成目标检测图像。

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

### C++版本

C++程序运行结束后,会在build目录生成目标检测图像。
Your Name's avatar
Your Name committed
160

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

liucong's avatar
liucong committed
163
164
165
166
### 精度



liucong's avatar
liucong committed
167
168
169
170
171
172
173
## 应用场景

### 算法类别

`目标检测`

### 热点应用行业
Your Name's avatar
Your Name committed
174

liucong's avatar
liucong committed
175
`交通`,`教育`,`化工`
Your Name's avatar
Your Name committed
176

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

chenzk's avatar
chenzk committed
179
https://developer.sourcefind.cn/codes/modelzoo/yolov7_migraphx
Your Name's avatar
Your Name committed
180

liucong's avatar
liucong committed
181
## 参考资料
Your Name's avatar
Your Name committed
182

liucong's avatar
liucong committed
183
https://github.com/WongKinYiu/yolov7