README.md 3.59 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
38
39
40
41
42
43
44
45
46
47
48
创建并启动容器:

```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
```

## 数据集

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

## 推理

### Python版本推理

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

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

shizhm's avatar
shizhm committed
50
51
52
53
```
export PYTHONPATH=/opt/dtk/lib:$PYTHONPATH
```

liucong's avatar
liucong committed
54
#### 安装依赖
liucong's avatar
liucong committed
55
56
57

```
# 进入python示例目录
shizhm's avatar
shizhm committed
58
cd <path_to_yolov3_migraphx>/Python
liucong's avatar
liucong committed
59
60

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

liucong's avatar
liucong committed
64
#### 运行示例
shizhm's avatar
shizhm committed
65

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

shizhm's avatar
shizhm committed
68
```
liucong's avatar
liucong committed
69
70
71
72
73
74
75
76
python YoloV3_infer_migraphx.py \
	--imgpath 测试图像路径 \ 
	--modelpath onnx模型路径 \
	--objectThreshold 判断是否有物体阈值,默认0.4 \
	--confThreshold 置信度阈值,默认0.2 \
	--nmsThreshold nms阈值,默认0.4 \
```

liucong's avatar
liucong committed
77
### C++版本推理
liucong's avatar
liucong committed
78

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


liucong's avatar
liucong committed
82
#### 构建工程
Your Name's avatar
Your Name committed
83

Your Name's avatar
Your Name committed
84
```
Your Name's avatar
Your Name committed
85
86
87
rbuild build -d depend
```

liucong's avatar
liucong committed
88
#### 设置环境变量
Your Name's avatar
Your Name committed
89

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

Your Name's avatar
Your Name committed
92
```
shizhm's avatar
shizhm committed
93
export LD_LIBRARY_PATH=<path_to_yolov3_migraphx>/depend/lib64/:$LD_LIBRARY_PATH
Your Name's avatar
Your Name committed
94
95
96
97
98
99
100
101
```

然后执行:

```
source ~/.bashrc
```

liucong's avatar
liucong committed
102
#### 运行示例
Your Name's avatar
Your Name committed
103

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

```
shizhm's avatar
shizhm committed
107
# 进入yolov3 migraphx工程根目录
shizhm's avatar
shizhm committed
108
cd <path_to_yolov3_migraphx> 
Your Name's avatar
Your Name committed
109

liucong's avatar
liucong committed
110
111
# 进入build目录
cd ./build/
Your Name's avatar
Your Name committed
112

liucong's avatar
liucong committed
113
114
# 执行示例程序
./YOLOV3
Your Name's avatar
Your Name committed
115
116
```

liucong's avatar
liucong committed
117
118
119
120
121
122
123
124
125
126
127
## 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
128

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

liucong's avatar
liucong committed
131
132
133
134
135
136
137
138
139
140
## 应用场景

### 算法类别

`目标检测`

### 热点应用行业

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

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

liucong's avatar
liucong committed
143
https://developer.hpccube.com/codes/modelzoo/yolov3_migraphx
Your Name's avatar
Your Name committed
144
145
146

## 参考

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