README.md 4.05 KB
Newer Older
Your Name's avatar
Your Name committed
1
# YoloV3
liucong's avatar
liucong committed
2
## 论文
Rayyyyy's avatar
Rayyyyy committed
3
`YOLOv3: An Incremental Improvement`
liucong's avatar
liucong committed
4
- https://arxiv.org/abs/1804.02767
Your Name's avatar
Your Name committed
5
6

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

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

liucong's avatar
liucong committed
11
12
## 算法原理
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
13

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

liucong's avatar
liucong committed
16
## 环境配置
liucong's avatar
liucong committed
17
### Docker(方法一)
liucong's avatar
liucong committed
18
19
20
21
拉取镜像:

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

liucong's avatar
liucong committed
24
25
26
27
28
29
30
31
32
创建并启动容器:

```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
33
34
35
36
37
38
### 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
39
40
41

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

liucong's avatar
liucong committed
44
45
46
47
48
49
50
51
## 数据集
根据提供的样本数据,进行目标检测。

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

#### 设置环境变量
shizhm's avatar
shizhm committed
52
53
54
55
```
export PYTHONPATH=/opt/dtk/lib:$PYTHONPATH
```

liucong's avatar
liucong committed
56
#### 安装依赖
liucong's avatar
liucong committed
57
58
```
# 进入python示例目录
shizhm's avatar
shizhm committed
59
cd <path_to_yolov3_migraphx>/Python
liucong's avatar
liucong committed
60
61

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

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

liucong's avatar
liucong committed
77
### C++版本推理
shizhm's avatar
shizhm committed
78
79
80
下面介绍如何运行C++代码示例,C++示例的详细说明见Doc目录下的Tutorial_Cpp.md。


liucong's avatar
liucong committed
81
#### 构建工程
Your Name's avatar
Your Name committed
82
```
Your Name's avatar
Your Name committed
83
84
85
rbuild build -d depend
```

liucong's avatar
liucong committed
86
#### 设置环境变量
Your Name's avatar
Your Name committed
87
88
将依赖库依赖加入环境变量LD_LIBRARY_PATH,在~/.bashrc中添加如下语句:

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

然后执行:

```
source ~/.bashrc
```

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

```
shizhm's avatar
shizhm committed
103
# 进入yolov3 migraphx工程根目录
Rayyyyy's avatar
Rayyyyy committed
104
cd <path_to_yolov3_migraphx>
Your Name's avatar
Your Name committed
105

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

liucong's avatar
liucong committed
109
110
# 执行示例程序
./YOLOV3
Your Name's avatar
Your Name committed
111
112
```

liucong's avatar
liucong committed
113
114
115
116
117
118
119
120
## 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
121

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

liucong's avatar
liucong committed
124
125
126
### 精度


liucong's avatar
liucong committed
127
128
129
## 应用场景

### 算法类别
Rayyyyy's avatar
Rayyyyy committed
130
目标检测
liucong's avatar
liucong committed
131
132

### 热点应用行业
Rayyyyy's avatar
Rayyyyy committed
133
交通,教育,化工
liucong's avatar
liucong committed
134

shizhm's avatar
shizhm committed
135
## 源码仓库及问题反馈
Rayyyyy's avatar
Rayyyyy committed
136
- https://developer.hpccube.com/codes/modelzoo/yolov3_migraphx
Your Name's avatar
Your Name committed
137

liucong's avatar
liucong committed
138
## 参考资料
Rayyyyy's avatar
Rayyyyy committed
139
- https://github.com/ultralytics/yolov3