README.md 4.57 KB
Newer Older
dcuai's avatar
dcuai 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
拉取镜像:

```plaintext
liucong's avatar
liucong committed
21
docker pull image.sourcefind.cn:5000/dcu/admin/base/migraphx:4.3.0-ubuntu20.04-dtk24.04.1-py3.10
Your Name's avatar
Your Name committed
22
```
Your Name's avatar
Your Name committed
23

liucong's avatar
liucong committed
24
25
26
创建并启动容器:

```plaintext
liucong's avatar
liucong committed
27
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 -v /opt/hyhal:/opt/hyhal:ro -it <Your Image ID> /bin/bash
liucong's avatar
liucong committed
28
29
30
31
32

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

liucong's avatar
liucong committed
33
34
35
36
37
### Dockerfile(方法二)
```
cd ./docker
docker build --no-cache -t yolov3_migraphx:2.0 .

liucong's avatar
liucong committed
38
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 -v /opt/hyhal:/opt/hyhal:ro -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++版本推理
liucong's avatar
liucong committed
78

liucong's avatar
liucong committed
79
注意:当使用操作系统不一样时,CMakeList需要做相应的修改:
liucong's avatar
liucong committed
80
81
82
83
84
85
86
87
88

```
# ubuntu操作系统
${CMAKE_CURRENT_SOURCE_DIR}/depend/lib64/ 修改为 ${CMAKE_CURRENT_SOURCE_DIR}/depend/lib/

# centos操作系统
${CMAKE_CURRENT_SOURCE_DIR}/depend/lib/ 修改为 ${CMAKE_CURRENT_SOURCE_DIR}/depend/lib64/
```

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


liucong's avatar
liucong 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
99
将依赖库依赖加入环境变量LD_LIBRARY_PATH,在~/.bashrc中添加如下语句:

liucong's avatar
liucong committed
100
101
102
103
104
105
106
107
当操作系统是ubuntu系统时:

```
export LD_LIBRARY_PATH=<path_to_yolov3_migraphx>/depend/lib/:$LD_LIBRARY_PATH
```

当操作系统是centos系统时:

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
#### 运行示例
liucong's avatar
liucong committed
119
成功编译YoloV3工程后,执行如下命令运行该示例:
Your Name's avatar
Your Name committed
120
121

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

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

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

liucong's avatar
liucong committed
132
133
134
135
136
137
138
139
## 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
140

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

liucong's avatar
liucong committed
143
144
145
### 精度


liucong's avatar
liucong committed
146
147
148
## 应用场景

### 算法类别
Rayyyyy's avatar
Rayyyyy committed
149
目标检测
liucong's avatar
liucong committed
150
151

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

shizhm's avatar
shizhm committed
154
## 源码仓库及问题反馈
chenzk's avatar
chenzk committed
155
- https://developer.sourcefind.cn/codes/modelzoo/yolov3_migraphx
Your Name's avatar
Your Name committed
156

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