README.md 3.98 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
## 环境配置
Your Name's avatar
Your Name committed
20

liucong's avatar
liucong committed
21
### Docker(方法一)
Your Name's avatar
Your Name committed
22

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

```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
27
```
Your Name's avatar
Your Name committed
28

liucong's avatar
liucong committed
29
30
31
32
33
34
35
36
37
创建并启动容器:

```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
38
39
40
41
42
43
44
45
46
### 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
47
48
49
50
51
52
53
54
55
56
57
## 数据集

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

## 推理

### Python版本推理

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

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

shizhm's avatar
shizhm committed
59
60
61
62
```
export PYTHONPATH=/opt/dtk/lib:$PYTHONPATH
```

liucong's avatar
liucong committed
63
#### 安装依赖
liucong's avatar
liucong committed
64
65
66

```
# 进入python示例目录
shizhm's avatar
shizhm committed
67
cd <path_to_yolov3_migraphx>/Python
liucong's avatar
liucong committed
68
69

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

liucong's avatar
liucong committed
73
#### 运行示例
shizhm's avatar
shizhm committed
74

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

shizhm's avatar
shizhm committed
77
```
liucong's avatar
liucong committed
78
79
80
81
82
83
84
85
python YoloV3_infer_migraphx.py \
	--imgpath 测试图像路径 \ 
	--modelpath onnx模型路径 \
	--objectThreshold 判断是否有物体阈值,默认0.4 \
	--confThreshold 置信度阈值,默认0.2 \
	--nmsThreshold nms阈值,默认0.4 \
```

liucong's avatar
liucong committed
86
### C++版本推理
liucong's avatar
liucong committed
87

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


liucong's avatar
liucong committed
91
#### 构建工程
Your Name's avatar
Your Name committed
92

Your Name's avatar
Your Name committed
93
```
Your Name's avatar
Your Name committed
94
95
96
rbuild build -d depend
```

liucong's avatar
liucong committed
97
#### 设置环境变量
Your Name's avatar
Your Name committed
98

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

Your Name's avatar
Your Name committed
101
```
shizhm's avatar
shizhm committed
102
export LD_LIBRARY_PATH=<path_to_yolov3_migraphx>/depend/lib64/:$LD_LIBRARY_PATH
Your Name's avatar
Your Name committed
103
104
105
106
107
108
109
110
```

然后执行:

```
source ~/.bashrc
```

liucong's avatar
liucong committed
111
#### 运行示例
Your Name's avatar
Your Name committed
112

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

```
shizhm's avatar
shizhm committed
116
# 进入yolov3 migraphx工程根目录
shizhm's avatar
shizhm committed
117
cd <path_to_yolov3_migraphx> 
Your Name's avatar
Your Name committed
118

liucong's avatar
liucong committed
119
120
# 进入build目录
cd ./build/
Your Name's avatar
Your Name committed
121

liucong's avatar
liucong committed
122
123
# 执行示例程序
./YOLOV3
Your Name's avatar
Your Name committed
124
125
```

liucong's avatar
liucong committed
126
127
128
129
130
131
132
133
134
135
136
## 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
137

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

liucong's avatar
liucong committed
140
141
142
143
### 精度



liucong's avatar
liucong committed
144
145
146
147
148
149
150
151
152
153
## 应用场景

### 算法类别

`目标检测`

### 热点应用行业

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

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

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

liucong's avatar
liucong committed
158
## 参考资料
Your Name's avatar
Your Name committed
159

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