README.md 3.08 KB
Newer Older
Your Name's avatar
Your Name committed
1
# YoloV3
shizhm's avatar
shizhm committed
2

Your Name's avatar
Your Name committed
3
4
5
6
7
8
9
10
## 模型介绍

YOLOV3是由Joseph Redmon和Ali Farhadi在2018年提出的单阶段目标检测模型,主要用于自然场景的目标检测。

## 模型结构

算法基本思想首先通过特征提取网络对输入提取特征,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误差和分类误差。参考论文地址:https://arxiv.org/abs/1804.02767

shizhm's avatar
shizhm committed
11
## Python版本推理
liucong's avatar
liucong committed
12

shizhm's avatar
shizhm committed
13
下面介绍如何运行Python代码示例,Python示例的详细说明见Doc目录下的Tutorial_Python.md。
liucong's avatar
liucong committed
14

shizhm's avatar
shizhm committed
15
### 下载镜像
Your Name's avatar
Your Name committed
16
17

在光源可拉取推理的docker镜像,YoloV3工程推荐的镜像如下:
Your Name's avatar
Your Name committed
18

Your Name's avatar
Your Name committed
19
20
21
```python
docker pull image.sourcefind.cn:5000/dcu/admin/base/custom:ort1.14.0_migraphx3.0.0-dtk22.10.1
```
Your Name's avatar
Your Name committed
22

shizhm's avatar
shizhm committed
23
### 设置Python环境变量
liucong's avatar
liucong committed
24

shizhm's avatar
shizhm committed
25
26
27
28
29
```
export PYTHONPATH=/opt/dtk/lib:$PYTHONPATH
```

### 安装依赖
liucong's avatar
liucong committed
30
31
32

```
# 进入python示例目录
shizhm's avatar
shizhm committed
33
cd <path_to_yolov3_migraphx>/Python
liucong's avatar
liucong committed
34
35
36

# 安装依赖
pip install -r requirements.txt
shizhm's avatar
shizhm committed
37
38
39
40
```

### 运行示例

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

shizhm's avatar
shizhm committed
43
```
liucong's avatar
liucong committed
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
python YoloV3_infer_migraphx.py \
	--imgpath 测试图像路径 \ 
	--modelpath onnx模型路径 \
	--objectThreshold 判断是否有物体阈值,默认0.4 \
	--confThreshold 置信度阈值,默认0.2 \
	--nmsThreshold nms阈值,默认0.4 \
```

程序运行结束会在当前目录生成YoloV3检测结果图像。

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



## C++版本推理

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

### 下载镜像

在光源中下载MIGraphX镜像: 
liucong's avatar
liucong committed
65

shizhm's avatar
shizhm committed
66
67
68
```
docker pull image.sourcefind.cn:5000/dcu/admin/base/custom:ort1.14.0_migraphx3.0.0-dtk22.10.1
```
liucong's avatar
liucong committed
69

Your Name's avatar
Your Name committed
70

shizhm's avatar
shizhm committed
71
### 构建工程
Your Name's avatar
Your Name committed
72

Your Name's avatar
Your Name committed
73
```
Your Name's avatar
Your Name committed
74
75
76
77
rbuild build -d depend
```

### 设置环境变量
Your Name's avatar
Your Name committed
78

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

Your Name's avatar
Your Name committed
81
```
shizhm's avatar
shizhm committed
82
export LD_LIBRARY_PATH=<path_to_yolov3_migraphx>/depend/lib64/:$LD_LIBRARY_PATH
Your Name's avatar
Your Name committed
83
84
85
86
87
88
89
90
```

然后执行:

```
source ~/.bashrc
```

shizhm's avatar
shizhm committed
91
### 运行示例
Your Name's avatar
Your Name committed
92

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

```
shizhm's avatar
shizhm committed
96
# 进入yolov3 migraphx工程根目录
shizhm's avatar
shizhm committed
97
cd <path_to_yolov3_migraphx> 
Your Name's avatar
Your Name committed
98

liucong's avatar
liucong committed
99
100
# 进入build目录
cd ./build/
Your Name's avatar
Your Name committed
101

liucong's avatar
liucong committed
102
103
# 执行示例程序
./YOLOV3
Your Name's avatar
Your Name committed
104
105
```

liucong's avatar
liucong committed
106
程序运行结束会在build目录生成YoloV3检测结果图像。
Your Name's avatar
Your Name committed
107

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

shizhm's avatar
shizhm committed
110
## 源码仓库及问题反馈
Your Name's avatar
Your Name committed
111
112
113
114
115
116

​		https://developer.hpccube.com/codes/modelzoo/yolov3_migraphx

## 参考

​		https://github.com/ultralytics/yolov3