README.md 4.08 KB
Newer Older
Your Name's avatar
Your Name committed
1
# YoloV3
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
YOLOv3: An Incremental Improvement

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

## 模型结构

liucong's avatar
liucong committed
11
YOLOV3是由Joseph Redmon和Ali Farhadi在2018年提出的单阶段目标检测模型,主要用于自然场景的目标检测。
Your Name's avatar
Your Name committed
12

liucong's avatar
liucong committed
13
<img src="./Doc/YOLOV3_01.jpg" style="zoom:100%;" align=middle>
liucong's avatar
liucong committed
14

liucong's avatar
liucong committed
15
16
17
## 算法原理

Yolov3算法的基本思想:首先通过特征提取网络对输入提取特征,backbone部分由YOLOV2时期的Darknet19进化至Darknet53加深了网络层数,引入了Resnet中的跨层加和操作;然后结合不同卷积层的特征实现多尺度训练,一共有13x13、26x26、52x52三种分辨率,分别用来预测大、中、小的物体;每种分辨率的特征图将输入图像分成不同数量的格子,每个格子预测B个bounding box,每个bounding box预测内容包括: Location(x, y, w, h)、Confidence Score和C个类别的概率,因此YOLOv3输出层的channel数为B*(5 + C)。YOLOv3的loss函数也有三部分组成:Location误差,Confidence误差和分类误差。
liucong's avatar
liucong committed
18

liucong's avatar
liucong committed
19
20
21
22
<img src="./Doc/YOLOV3_02.png" style="zoom:100%;" align=middle>



liucong's avatar
liucong committed
23
## 环境配置
Your Name's avatar
Your Name committed
24

liucong's avatar
liucong committed
25
### Docker(方法一)
Your Name's avatar
Your Name committed
26

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

```plaintext
docker pull image.sourcefind.cn:5000/dcu/admin/base/migraphx:4.0.0-centos7.6-dtk23.04.1-py38-latest
Your Name's avatar
Your Name committed
31
```
Your Name's avatar
Your Name committed
32

liucong's avatar
liucong committed
33
34
35
36
37
38
39
40
41
创建并启动容器:

```plaintext
docker run --shm-size 16g --network=host --name=yolov3_migraphx --privileged --device=/dev/kfd --device=/dev/dri --group-add video --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -v $PWD/yolov3_migraphx:/home/yolov3_migraphx -it <Your Image ID> /bin/bash

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

liucong's avatar
liucong committed
42
43
44
45
46
47
48
### Dockerfile(方法二)

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

docker run --shm-size 16g --network=host --name=yolov3_migraphx --privileged --device=/dev/kfd --device=/dev/dri --group-add video --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -v $PWD/yolov3_migraphx:/home/yolov3_migraphx -it <Your Image ID> /bin/bash
liucong's avatar
liucong committed
49
50
51

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

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

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

## 推理

### Python版本推理

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

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

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

liucong's avatar
liucong committed
70
#### 安装依赖
liucong's avatar
liucong committed
71
72
73

```
# 进入python示例目录
shizhm's avatar
shizhm committed
74
cd <path_to_yolov3_migraphx>/Python
liucong's avatar
liucong committed
75
76

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

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

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

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

liucong's avatar
liucong committed
93
### C++版本推理
liucong's avatar
liucong committed
94

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


liucong's avatar
liucong committed
98
#### 构建工程
Your Name's avatar
Your Name committed
99

Your Name's avatar
Your Name committed
100
```
Your Name's avatar
Your Name committed
101
102
103
rbuild build -d depend
```

liucong's avatar
liucong committed
104
#### 设置环境变量
Your Name's avatar
Your Name committed
105

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

Your Name's avatar
Your Name committed
108
```
shizhm's avatar
shizhm committed
109
export LD_LIBRARY_PATH=<path_to_yolov3_migraphx>/depend/lib64/:$LD_LIBRARY_PATH
Your Name's avatar
Your Name committed
110
111
112
113
114
115
116
117
```

然后执行:

```
source ~/.bashrc
```

liucong's avatar
liucong committed
118
#### 运行示例
Your Name's avatar
Your Name committed
119

liucong's avatar
liucong committed
120
成功编译YoloV3工程后,执行如下命令运行该示例:
Your Name's avatar
Your Name committed
121
122

```
shizhm's avatar
shizhm committed
123
# 进入yolov3 migraphx工程根目录
shizhm's avatar
shizhm committed
124
cd <path_to_yolov3_migraphx> 
Your Name's avatar
Your Name committed
125

liucong's avatar
liucong committed
126
127
# 进入build目录
cd ./build/
Your Name's avatar
Your Name committed
128

liucong's avatar
liucong committed
129
130
# 执行示例程序
./YOLOV3
Your Name's avatar
Your Name committed
131
132
```

liucong's avatar
liucong committed
133
134
135
136
137
138
139
140
141
142
143
## result

### Python版本

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

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

### C++版本

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

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

liucong's avatar
liucong committed
147
148
149
150
### 精度



liucong's avatar
liucong committed
151
152
153
154
155
156
157
158
159
160
## 应用场景

### 算法类别

`目标检测`

### 热点应用行业

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

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

liucong's avatar
liucong committed
163
https://developer.hpccube.com/codes/modelzoo/yolov3_migraphx
Your Name's avatar
Your Name committed
164

liucong's avatar
liucong committed
165
## 参考资料
Your Name's avatar
Your Name committed
166

liucong's avatar
liucong committed
167
https://github.com/ultralytics/yolov3