README.md 3.19 KB
Newer Older
Your Name's avatar
Your Name committed
1
# YoloV7
shizhm's avatar
shizhm committed
2

Your Name's avatar
Your Name committed
3
4
5
6
7
8
## 模型介绍

YOLOV7是2022年最新出现的一种YOLO系列目标检测模型,在论文 [YOLOv7: Trainable bag-of-freebies sets new state-of-the-art for real-time object detectors](https://arxiv.org/abs/2207.02696)中提出。

## 模型结构

Your Name's avatar
Your Name committed
9
YoloV7模型的网络结构包括三个部分:input、backbone和head。与yolov5不同的是,将neck层与head层合称为head层,实际上的功能是一样的。各个部分的功能和yolov5相同,如backbone用于提取特征,head用于预测。yolov7依旧基于anchor based的方法,同时在网络架构上增加E-ELAN层,并将REP层也加入进来,方便后续部署,同时在训练时,在head时,新增Aux_detect用于辅助检测。
Your Name's avatar
Your Name committed
10

liucong's avatar
liucong committed
11
12
13
14
## python版本推理

下面介绍如何运行python代码示例,具体推理代码解析,在Doc/Tutorial_Python.md中有详细说明。

liucong's avatar
liucong committed
15
### 拉取镜像
Your Name's avatar
Your Name committed
16
17

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

Your Name's avatar
Your Name committed
19
20
21
```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
22

liucong's avatar
liucong committed
23
24
25
26
27
28
### 推理示例

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

```
# 进入python示例目录
shizhm's avatar
shizhm committed
29
cd <path_to_yolov7_migraphx>/Python
liucong's avatar
liucong committed
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52

# 安装依赖
pip install -r requirements.txt

# 运行程序
python YoloV7_infer_migraphx.py \
	--imgpath 测试图像路径 \ 
	--modelpath onnx模型路径 \
	--objectThreshold 判断是否有物体阈值,默认0.5 \
	--confThreshold 置信度阈值,默认0.25 \
	--nmsThreshold nms阈值,默认0.5 \
```

程序运行结束会在当前目录生成YoloV7检测结果图像。

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

## C++版本推理

下面介绍如何运行C++代码示例,具体推理代码解析,在Doc/Tutorial_Cpp.md目录中有详细说明。

参考Python版本推理中的构建安装,在光源中拉取推理的docker镜像。

Your Name's avatar
Your Name committed
53
### 安装Opencv依赖
Your Name's avatar
Your Name committed
54

Your Name's avatar
Your Name committed
55
56
57
```python
cd <path_to_migraphx_samples>
sh ./3rdParty/InstallOpenCVDependences.sh
Your Name's avatar
Your Name committed
58
```
Your Name's avatar
Your Name committed
59
60
61
62
63
64
65
66
67
68
69

### 修改CMakeLists.txt

- 如果使用ubuntu系统,需要修改CMakeLists.txt中依赖库路径:
  将"${CMAKE_CURRENT_SOURCE_DIR}/depend/lib64/"修改为"${CMAKE_CURRENT_SOURCE_DIR}/depend/lib/"

- **MIGraphX2.3.0及以上版本需要c++17**


### 安装OpenCV并构建工程

Your Name's avatar
Your Name committed
70
```
Your Name's avatar
Your Name committed
71
72
73
74
rbuild build -d depend
```

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

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

**Centos**:
Your Name's avatar
Your Name committed
79
80

```
shizhm's avatar
shizhm committed
81
export LD_LIBRARY_PATH=<path_to_yolov7_migraphx>/depend/lib64/:$LD_LIBRARY_PATH
Your Name's avatar
Your Name committed
82
83
84
85
86
```

**Ubuntu**:

```
shizhm's avatar
shizhm committed
87
export LD_LIBRARY_PATH=<path_to_yolov7_migraphx>/depend/lib/:$LD_LIBRARY_PATH
Your Name's avatar
Your Name committed
88
89
```

Your Name's avatar
Your Name committed
90
91
92
93
94
95
然后执行:

```
source ~/.bashrc
```

liucong's avatar
liucong committed
96
### 推理示例
Your Name's avatar
Your Name committed
97

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

```
liucong's avatar
liucong committed
101
# 进入migraphx samples工程根目录
shizhm's avatar
shizhm committed
102
cd <path_to_yolov7_migraphx> 
Your Name's avatar
Your Name committed
103

liucong's avatar
liucong committed
104
105
# 进入build目录
cd ./build/
Your Name's avatar
Your Name committed
106

liucong's avatar
liucong committed
107
108
# 执行示例程序
./YOLOV7
Your Name's avatar
Your Name committed
109
```
Your Name's avatar
Your Name committed
110

liucong's avatar
liucong committed
111
程序运行结束会在build目录生成YoloV7检测结果图像。
Your Name's avatar
Your Name committed
112

liucong's avatar
liucong committed
113
<img src="./Resource/Images/Result.jpg" alt="Result" style="zoom:50%;" />
Your Name's avatar
Your Name committed
114
115
116
117
118



## 历史版本

Your Name's avatar
Your Name committed
119
​		https://developer.hpccube.com/codes/modelzoo/yolov7_migraphx
Your Name's avatar
Your Name committed
120
121
122

## 参考

Your Name's avatar
Your Name committed
123
​		https://github.com/WongKinYiu/yolov7