Darknet是一个轻型的深度学习和训练框架,从这一点上,它和tensorflow以及pytorch这种没有什么不同,特点在轻型二字,它主要对卷集神经网络进行了底层实现,并且主要用于YOLO的目标检测,特点主要有:

  1. C语言实现
  2. 没有依赖项,除了opencv进行视频和UVC摄像头处理
  3. 容易安装,可移植性好
  4. 支持CPU于GPU(CUDA)两种计算方式

下面开始实验。

下载代码,编译

git clone https://github.com/AlexeyAB/darknet
cd darknet
make

Ubuntu18.04 搭建YOLOV4环境_1024程序员节

 下载预训练权重:

Ubuntu18.04 搭建YOLOV4环境_pytorch_02

 验证:

caozilong@caozilong-Vostro-3268:~/Workspace/yolo/darknet$ ./darknet detector test ./cfg/coco.data ./cfg/yolov4.cfg ./yolov4.weights data/dog.jpg
GPU isn't used
OpenCV isn't used - data augmentation will be slow
mini_batch = 1, batch = 8, time_steps = 1, train = 0
layer filters size/strd(dil) input output
0 conv 32 3 x 3/ 1 608 x 608 x 3 -> 608 x 608 x 32 0.639 BF
1 conv 64 3 x 3/ 2 608 x 608 x 32 -> 304 x 304 x 64 3.407 BF
2 conv 64 1 x 1/ 1 304 x 304 x 64 -> 304 x 304 x 64 0.757 BF
3 route 1 -> 304 x 304 x 64
4 conv 64 1 x 1/ 1 304 x 304 x 64 -> 304 x 304 x 64 0.757 BF
5 conv 32 1 x 1/ 1 304 x 304 x 64 -> 304 x 304 x 32 0.379 BF
6 conv 64 3 x 3/ 1 304 x 304 x 32 -> 304 x 304 x 64 3.407 BF
7 Shortcut Layer: 4, wt = 0, wn = 0, outputs: 304 x 304 x 64 0.006 BF
8 conv 64 1 x 1/ 1 304 x 304 x 64 -> 304 x 304 x 64 0.757 BF
9 route 8 2 -> 304 x 304 x 128
10 conv 64 1 x 1/ 1 304 x 304 x 128 -> 304 x 304 x 64 1.514 BF
11 conv 128 3 x 3/ 2 304 x 304 x 64 -> 152 x 152 x 128 3.407 BF
12 conv 64 1 x 1/ 1 152 x 152 x 128 -> 152 x 152 x 64 0.379 BF
13 route 11 -> 152 x 152 x 128
14 conv 64 1 x 1/ 1 152 x 152 x 128 -> 152 x 152 x 64 0.379 BF
15 conv 64 1 x 1/ 1 152 x 152 x 64 -> 152 x 152 x 64 0.189 BF
16 conv 64 3 x 3/ 1 152 x 152 x 64 -> 152 x 152 x 64 1.703 BF
17 Shortcut Layer: 14, wt = 0, wn = 0, outputs: 152 x 152 x 64 0.001 BF
18 conv 64 1 x 1/ 1 152 x 152 x 64 -> 152 x 152 x 64 0.189 BF
19 conv 64 3 x 3/ 1 152 x 152 x 64 -> 152 x 152 x 64 1.703 BF
20 Shortcut Layer: 17, wt = 0, wn = 0, outputs: 152 x 152 x 64 0.001 BF
21 conv 64 1 x 1/ 1 152 x 152 x 64 -> 152 x 152 x 64 0.189 BF
22 route 21 12 -> 152 x 152 x 128
23 conv 128 1 x 1/ 1 152 x 152 x 128 -> 152 x 152 x 128 0.757 BF
24 conv 256 3 x 3/ 2 152 x 152 x 128 -> 76 x 76 x 256 3.407 BF
25 conv 128 1 x 1/ 1 76 x 76 x 256 -> 76 x 76 x 128 0.379 BF
26 route 24 -> 76 x 76 x 256
27 conv 128 1 x 1/ 1 76 x 76 x 256 -> 76 x 76 x 128 0.379 BF
28 conv 128 1 x 1/ 1 76 x 76 x 128 -> 76 x 76 x 128 0.189 BF
29 conv 128 3 x 3/ 1 76 x 76 x 128 -> 76 x 76 x 128 1.703 BF
30 Shortcut Layer: 27, wt = 0, wn = 0, outputs: 76 x 76 x 128 0.001 BF
31 conv 128 1 x 1/ 1 76 x 76 x 128 -> 76 x 76 x 128 0.189 BF
32 conv 128 3 x 3/ 1 76 x 76 x 128 -> 76 x 76 x 128 1.703 BF
33 Shortcut Layer: 30, wt = 0, wn = 0, outputs: 76 x 76 x 128 0.001 BF
34 conv 128 1 x 1/ 1 76 x 76 x 128 -> 76 x 76 x 128 0.189 BF
35 conv 128 3 x 3/ 1 76 x 76 x 128 -> 76 x 76 x 128 1.703 BF
36 Shortcut Layer: 33, wt = 0, wn = 0, outputs: 76 x 76 x 128 0.001 BF
37 conv 128 1 x 1/ 1 76 x 76 x 128 -> 76 x 76 x 128 0.189 BF
38 conv 128 3 x 3/ 1 76 x 76 x 128 -> 76 x 76 x 128 1.703 BF
39 Shortcut Layer: 36, wt = 0, wn = 0, outputs: 76 x 76 x 128 0.001 BF
40 conv 128 1 x 1/ 1 76 x 76 x 128 -> 76 x 76 x 128 0.189 BF
41 conv 128 3 x 3/ 1 76 x 76 x 128 -> 76 x 76 x 128 1.703 BF
42 Shortcut Layer: 39, wt = 0, wn = 0, outputs: 76 x 76 x 128 0.001 BF
43 conv 128 1 x 1/ 1 76 x 76 x 128 -> 76 x 76 x 128 0.189 BF
44 conv 128 3 x 3/ 1 76 x 76 x 128 -> 76 x 76 x 128 1.703 BF
45 Shortcut Layer: 42, wt = 0, wn = 0, outputs: 76 x 76 x 128 0.001 BF
46 conv 128 1 x 1/ 1 76 x 76 x 128 -> 76 x 76 x 128 0.189 BF
47 conv 128 3 x 3/ 1 76 x 76 x 128 -> 76 x 76 x 128 1.703 BF
48 Shortcut Layer: 45, wt = 0, wn = 0, outputs: 76 x 76 x 128 0.001 BF
49 conv 128 1 x 1/ 1 76 x 76 x 128 -> 76 x 76 x 128 0.189 BF
50 conv 128 3 x 3/ 1 76 x 76 x 128 -> 76 x 76 x 128 1.703 BF
51 Shortcut Layer: 48, wt = 0, wn = 0, outputs: 76 x 76 x 128 0.001 BF
52 conv 128 1 x 1/ 1 76 x 76 x 128 -> 76 x 76 x 128 0.189 BF
53 route 52 25 -> 76 x 76 x 256
54 conv 256 1 x 1/ 1 76 x 76 x 256 -> 76 x 76 x 256 0.757 BF
55 conv 512 3 x 3/ 2 76 x 76 x 256 -> 38 x 38 x 512 3.407 BF
56 conv 256 1 x 1/ 1 38 x 38 x 512 -> 38 x 38 x 256 0.379 BF
57 route 55 -> 38 x 38 x 512
58 conv 256 1 x 1/ 1 38 x 38 x 512 -> 38 x 38 x 256 0.379 BF
59 conv 256 1 x 1/ 1 38 x 38 x 256 -> 38 x 38 x 256 0.189 BF
60 conv 256 3 x 3/ 1 38 x 38 x 256 -> 38 x 38 x 256 1.703 BF
61 Shortcut Layer: 58, wt = 0, wn = 0, outputs: 38 x 38 x 256 0.000 BF
62 conv 256 1 x 1/ 1 38 x 38 x 256 -> 38 x 38 x 256 0.189 BF
63 conv 256 3 x 3/ 1 38 x 38 x 256 -> 38 x 38 x 256 1.703 BF
64 Shortcut Layer: 61, wt = 0, wn = 0, outputs: 38 x 38 x 256 0.000 BF
65 conv 256 1 x 1/ 1 38 x 38 x 256 -> 38 x 38 x 256 0.189 BF
66 conv 256 3 x 3/ 1 38 x 38 x 256 -> 38 x 38 x 256 1.703 BF
67 Shortcut Layer: 64, wt = 0, wn = 0, outputs: 38 x 38 x 256 0.000 BF
68 conv 256 1 x 1/ 1 38 x 38 x 256 -> 38 x 38 x 256 0.189 BF
69 conv 256 3 x 3/ 1 38 x 38 x 256 -> 38 x 38 x 256 1.703 BF
70 Shortcut Layer: 67, wt = 0, wn = 0, outputs: 38 x 38 x 256 0.000 BF
71 conv 256 1 x 1/ 1 38 x 38 x 256 -> 38 x 38 x 256 0.189 BF
72 conv 256 3 x 3/ 1 38 x 38 x 256 -> 38 x 38 x 256 1.703 BF
73 Shortcut Layer: 70, wt = 0, wn = 0, outputs: 38 x 38 x 256 0.000 BF
74 conv 256 1 x 1/ 1 38 x 38 x 256 -> 38 x 38 x 256 0.189 BF
75 conv 256 3 x 3/ 1 38 x 38 x 256 -> 38 x 38 x 256 1.703 BF
76 Shortcut Layer: 73, wt = 0, wn = 0, outputs: 38 x 38 x 256 0.000 BF
77 conv 256 1 x 1/ 1 38 x 38 x 256 -> 38 x 38 x 256 0.189 BF
78 conv 256 3 x 3/ 1 38 x 38 x 256 -> 38 x 38 x 256 1.703 BF
79 Shortcut Layer: 76, wt = 0, wn = 0, outputs: 38 x 38 x 256 0.000 BF
80 conv 256 1 x 1/ 1 38 x 38 x 256 -> 38 x 38 x 256 0.189 BF
81 conv 256 3 x 3/ 1 38 x 38 x 256 -> 38 x 38 x 256 1.703 BF
82 Shortcut Layer: 79, wt = 0, wn = 0, outputs: 38 x 38 x 256 0.000 BF
83 conv 256 1 x 1/ 1 38 x 38 x 256 -> 38 x 38 x 256 0.189 BF
84 route 83 56 -> 38 x 38 x 512
85 conv 512 1 x 1/ 1 38 x 38 x 512 -> 38 x 38 x 512 0.757 BF
86 conv 1024 3 x 3/ 2 38 x 38 x 512 -> 19 x 19 x1024 3.407 BF
87 conv 512 1 x 1/ 1 19 x 19 x1024 -> 19 x 19 x 512 0.379 BF
88 route 86 -> 19 x 19 x1024
89 conv 512 1 x 1/ 1 19 x 19 x1024 -> 19 x 19 x 512 0.379 BF
90 conv 512 1 x 1/ 1 19 x 19 x 512 -> 19 x 19 x 512 0.189 BF
91 conv 512 3 x 3/ 1 19 x 19 x 512 -> 19 x 19 x 512 1.703 BF
92 Shortcut Layer: 89, wt = 0, wn = 0, outputs: 19 x 19 x 512 0.000 BF
93 conv 512 1 x 1/ 1 19 x 19 x 512 -> 19 x 19 x 512 0.189 BF
94 conv 512 3 x 3/ 1 19 x 19 x 512 -> 19 x 19 x 512 1.703 BF
95 Shortcut Layer: 92, wt = 0, wn = 0, outputs: 19 x 19 x 512 0.000 BF
96 conv 512 1 x 1/ 1 19 x 19 x 512 -> 19 x 19 x 512 0.189 BF
97 conv 512 3 x 3/ 1 19 x 19 x 512 -> 19 x 19 x 512 1.703 BF
98 Shortcut Layer: 95, wt = 0, wn = 0, outputs: 19 x 19 x 512 0.000 BF
99 conv 512 1 x 1/ 1 19 x 19 x 512 -> 19 x 19 x 512 0.189 BF
100 conv 512 3 x 3/ 1 19 x 19 x 512 -> 19 x 19 x 512 1.703 BF
101 Shortcut Layer: 98, wt = 0, wn = 0, outputs: 19 x 19 x 512 0.000 BF
102 conv 512 1 x 1/ 1 19 x 19 x 512 -> 19 x 19 x 512 0.189 BF
103 route 102 87 -> 19 x 19 x1024
104 conv 1024 1 x 1/ 1 19 x 19 x1024 -> 19 x 19 x1024 0.757 BF
105 conv 512 1 x 1/ 1 19 x 19 x1024 -> 19 x 19 x 512 0.379 BF
106 conv 1024 3 x 3/ 1 19 x 19 x 512 -> 19 x 19 x1024 3.407 BF
107 conv 512 1 x 1/ 1 19 x 19 x1024 -> 19 x 19 x 512 0.379 BF
108 max 5x 5/ 1 19 x 19 x 512 -> 19 x 19 x 512 0.005 BF
109 route 107 -> 19 x 19 x 512
110 max 9x 9/ 1 19 x 19 x 512 -> 19 x 19 x 512 0.015 BF
111 route 107 -> 19 x 19 x 512
112 max 13x13/ 1 19 x 19 x 512 -> 19 x 19 x 512 0.031 BF
113 route 112 110 108 107 -> 19 x 19 x2048
114 conv 512 1 x 1/ 1 19 x 19 x2048 -> 19 x 19 x 512 0.757 BF
115 conv 1024 3 x 3/ 1 19 x 19 x 512 -> 19 x 19 x1024 3.407 BF
116 conv 512 1 x 1/ 1 19 x 19 x1024 -> 19 x 19 x 512 0.379 BF
117 conv 256 1 x 1/ 1 19 x 19 x 512 -> 19 x 19 x 256 0.095 BF
118 upsample 2x 19 x 19 x 256 -> 38 x 38 x 256
119 route 85 -> 38 x 38 x 512
120 conv 256 1 x 1/ 1 38 x 38 x 512 -> 38 x 38 x 256 0.379 BF
121 route 120 118 -> 38 x 38 x 512
122 conv 256 1 x 1/ 1 38 x 38 x 512 -> 38 x 38 x 256 0.379 BF
123 conv 512 3 x 3/ 1 38 x 38 x 256 -> 38 x 38 x 512 3.407 BF
124 conv 256 1 x 1/ 1 38 x 38 x 512 -> 38 x 38 x 256 0.379 BF
125 conv 512 3 x 3/ 1 38 x 38 x 256 -> 38 x 38 x 512 3.407 BF
126 conv 256 1 x 1/ 1 38 x 38 x 512 -> 38 x 38 x 256 0.379 BF
127 conv 128 1 x 1/ 1 38 x 38 x 256 -> 38 x 38 x 128 0.095 BF
128 upsample 2x 38 x 38 x 128 -> 76 x 76 x 128
129 route 54 -> 76 x 76 x 256
130 conv 128 1 x 1/ 1 76 x 76 x 256 -> 76 x 76 x 128 0.379 BF
131 route 130 128 -> 76 x 76 x 256
132 conv 128 1 x 1/ 1 76 x 76 x 256 -> 76 x 76 x 128 0.379 BF
133 conv 256 3 x 3/ 1 76 x 76 x 128 -> 76 x 76 x 256 3.407 BF
134 conv 128 1 x 1/ 1 76 x 76 x 256 -> 76 x 76 x 128 0.379 BF
135 conv 256 3 x 3/ 1 76 x 76 x 128 -> 76 x 76 x 256 3.407 BF
136 conv 128 1 x 1/ 1 76 x 76 x 256 -> 76 x 76 x 128 0.379 BF
137 conv 256 3 x 3/ 1 76 x 76 x 128 -> 76 x 76 x 256 3.407 BF
138 conv 255 1 x 1/ 1 76 x 76 x 256 -> 76 x 76 x 255 0.754 BF
139 yolo
[yolo] params: iou loss: ciou (4), iou_norm: 0.07, obj_norm: 1.00, cls_norm: 1.00, delta_norm: 1.00, scale_x_y: 1.20
nms_kind: greedynms (1), beta = 0.600000
140 route 136 -> 76 x 76 x 128
141 conv 256 3 x 3/ 2 76 x 76 x 128 -> 38 x 38 x 256 0.852 BF
142 route 141 126 -> 38 x 38 x 512
143 conv 256 1 x 1/ 1 38 x 38 x 512 -> 38 x 38 x 256 0.379 BF
144 conv 512 3 x 3/ 1 38 x 38 x 256 -> 38 x 38 x 512 3.407 BF
145 conv 256 1 x 1/ 1 38 x 38 x 512 -> 38 x 38 x 256 0.379 BF
146 conv 512 3 x 3/ 1 38 x 38 x 256 -> 38 x 38 x 512 3.407 BF
147 conv 256 1 x 1/ 1 38 x 38 x 512 -> 38 x 38 x 256 0.379 BF
148 conv 512 3 x 3/ 1 38 x 38 x 256 -> 38 x 38 x 512 3.407 BF
149 conv 255 1 x 1/ 1 38 x 38 x 512 -> 38 x 38 x 255 0.377 BF
150 yolo
[yolo] params: iou loss: ciou (4), iou_norm: 0.07, obj_norm: 1.00, cls_norm: 1.00, delta_norm: 1.00, scale_x_y: 1.10
nms_kind: greedynms (1), beta = 0.600000
151 route 147 -> 38 x 38 x 256
152 conv 512 3 x 3/ 2 38 x 38 x 256 -> 19 x 19 x 512 0.852 BF
153 route 152 116 -> 19 x 19 x1024
154 conv 512 1 x 1/ 1 19 x 19 x1024 -> 19 x 19 x 512 0.379 BF
155 conv 1024 3 x 3/ 1 19 x 19 x 512 -> 19 x 19 x1024 3.407 BF
156 conv 512 1 x 1/ 1 19 x 19 x1024 -> 19 x 19 x 512 0.379 BF
157 conv 1024 3 x 3/ 1 19 x 19 x 512 -> 19 x 19 x1024 3.407 BF
158 conv 512 1 x 1/ 1 19 x 19 x1024 -> 19 x 19 x 512 0.379 BF
159 conv 1024 3 x 3/ 1 19 x 19 x 512 -> 19 x 19 x1024 3.407 BF
160 conv 255 1 x 1/ 1 19 x 19 x1024 -> 19 x 19 x 255 0.189 BF
161 yolo
[yolo] params: iou loss: ciou (4), iou_norm: 0.07, obj_norm: 1.00, cls_norm: 1.00, delta_norm: 1.00, scale_x_y: 1.05
nms_kind: greedynms (1), beta = 0.600000
Total BFLOPS 128.459
avg_outputs = 1068395
Loading weights from ./yolov4.weights...
seen 64, trained: 32032 K-images (500 Kilo-batches_64)
Done! Loaded 162 layers from weights-file
Detection layer: 139 - type = 28
Detection layer: 150 - type = 28
Detection layer: 161 - type = 28

data/dog.jpg: Predicted in 19868.358000 milli-seconds.
bicycle: 92%
dog: 98%
truck: 92%
pottedplant: 33%
Not compiled with OpenCV, saving to predictions.png instead
caozilong@caozilong-Vostro-3268:~/Workspace/yolo/darknet$

Ubuntu18.04 搭建YOLOV4环境_神经网络_03

./darknet detector test ./cfg/coco.data ./cfg/yolov4.cfg ./yolov4.weights data/person.jpg

Ubuntu18.04 搭建YOLOV4环境_1024程序员节_04

yolov4.cfg和yolov4.weights分别表示了yolo4的网络结构和训练好的网络权重,coco.data暂时不清楚是什么,应该表示数据集,coco.data中存放有指向训练数据集的路径。

补充:

时隔2月余,重新搭建环境再跑这两个用例,发现测试数据没有发生变化,这是否说明,对于同一个模型的同一个权重以及测试文件,测试结论是确定的,也就是说,预测结果不具有时变性?

Ubuntu18.04 搭建YOLOV4环境_深度学习_05

Ubuntu18.04 搭建YOLOV4环境_深度学习_06

设置-thresh 参数

thresh参数可以设置检测概率的阀值,只有大于等于这个阀值的目标物体才会被框出来。

Ubuntu18.04 搭建YOLOV4环境_神经网络_07

比如,当设置阀值为0.93时,只有狗狗被框了出来。

Ubuntu18.04 搭建YOLOV4环境_1024程序员节_08

用yolo3.weights测试:

下载yolov3.weights训练文件

wget -c https://pjreddie.com/media/files/yolov3.weights

Ubuntu18.04 搭建YOLOV4环境_1024程序员节_09

此时,可以执行如下命令进行yolo3的测试。

./darknet detector test ./cfg/coco.data ./cfg/yolov3.cfg ./yolov3.weights data/dog.jpg -i 0 -thresh 0.25

实时抓图显示:

可以通过python将darknet推理框架和opencv连接起来构成推理应用。连接UVC摄像头后,OpenCV通过V4L2框架抓取图片,然后送给darknet完成实时推理。演示的话,执行darknet目录下的darknet_video.py 文件 即可,事先必须要打开Makefile LIBSO变量重新编译,以生成脚本文件需要的动态库。

Ubuntu18.04 搭建YOLOV4环境_github_10

Ubuntu18.04 搭建YOLOV4环境_github_11

我的帅豆:

Ubuntu18.04 搭建YOLOV4环境_github_12

本用例是一个流式检测的用例,也就是视频的每一帧都要送给模型去推理,由于我使用的是集成显卡,算力不足以支撑流畅播放需要的帧率,所以看起来非常的卡顿,但实际上,推理是逐帧进行的。

Ubuntu18.04 搭建YOLOV4环境_深度学习_13

-out选项:

-out选项用于指定输出文件,输出文件为json格式,描述了测试输入和测试结果的情况,比如:

./darknet detector test ./cfg/coco.data ./cfg/yolov4.cfg ./yolov4.weights data/person.jpg -out out.json

输出的out.json内容为:

Ubuntu18.04 搭建YOLOV4环境_github_14

对应代码中的逻辑:

Ubuntu18.04 搭建YOLOV4环境_1024程序员节_15

Ubuntu18.04 搭建YOLOV4环境_神经网络_16

模型转换:

以darknet模型转换为例,NCNN编译完成后,darknet目录会生成转换工具darknet2ncnn

Ubuntu18.04 搭建YOLOV4环境_深度学习_17

 将yolov4模型转换为NCNN格式:

czl@czl-VirtualBox:~/WorkSpace/ncnn/build/tools/darknet$ ./darknet2ncnn /home/czl/WorkSpace/dark/darknet/cfg/yolov4.cfg /home/czl/WorkSpace/dark/darknet/cfg/yolov4.weights 
Loading cfg...
WARNING: The ignore_thresh=0.700000 of yolo0 is too high. An alternative value 0.25 is written instead.
WARNING: The ignore_thresh=0.700000 of yolo1 is too high. An alternative value 0.25 is written instead.
WARNING: The ignore_thresh=0.700000 of yolo2 is too high. An alternative value 0.25 is written instead.
Loading weights...
Converting model...
399 layers, 436 blobs generated.
NOTE: The input of darknet uses: mean_vals=0 and norm_vals=1/255.f.
NOTE: Remember to use ncnnoptimize for better performance.
czl@czl-VirtualBox:~/WorkSpace/ncnn/build/tools/darknet$ ls -l
total 251832
drwxrwxr-x 3 czl czl 4096 11月 4 13:52 CMakeFiles
-rw-rw-r-- 1 czl czl 1978 11月 4 13:52 cmake_install.cmake
-rwxrwxr-x 1 czl czl 101160 11月 4 13:59 darknet2ncnn
-rw-rw-r-- 1 czl czl 7673 11月 4 13:52 Makefile
-rw-rw-r-- 1 czl czl 257718060 11月 4 14:20 ncnn.bin
-rw-rw-r-- 1 czl czl 35901 11月 4 14:20 ncnn.param
czl@czl-VirtualBox:~/WorkSpace/ncnn/build/tools/darknet$

Ubuntu18.04 搭建YOLOV4环境_github_18

基于GPU运行YOLOV4视频检测:

参考这篇文章搭建GPU CUDA环境:

环境准备1.PC Host Ubuntu 18.04.6,Linux Kernel 5.4,内核版本关系不大,记录下来备查。2.安装基础工具,比如GCC,CMAKE,VIM,GIT等等,工具尽量完备, 如果做不到,遇到问题临时下载也可。3.安装python3发行版,我用的是anaconda发行版,具体版本是 Anaconda3-2020.11-Linux-x86_64.sh下载地址在如下链接,选择对应的版本即可。然后打开darknet/Makefile中的GPU,LIBSO,OPENCV三项: 

Ubuntu18.04 搭建YOLOV4环境_github_19

重新编译,之后运行 python darknet_video.py,测试发现画框随着视频播放已经很流畅了,可以得出GPU对提高网络的检测效率方面,提升非常明显。

Ubuntu18.04 搭建YOLOV4环境_深度学习_20

YOLOV4小模型推理:

YOLOV4小模型使用的模型结构文件是./cfg/yolov4-tiny.cfg文件,对应的权重从下面链接处下载:

wget -c https://github.com/AlexeyAB/darknet/releases/download/darknet_yolo_v4_pre/yolov4-tiny.weights

Ubuntu18.04 搭建YOLOV4环境_神经网络_21

Ubuntu18.04 搭建YOLOV4环境_神经网络_22

YOLOV4视频帧检测:

./darknet detector demo ./cfg/coco.data ./cfg/yolov4.cfg ./yolov4.weights /home/caozilong/onnx/FairMOT/videos/MOT16-03.mp4

检测效果如下图,可以看到帧率为4.8FPS,这是在开了GPU的情况下的情况,可以看到YOLOV4的计算量是比较大的,和YOLOV3的10FPS相比,可以得出YOLOV4比YOLOV3更吃算力。 

换为YOLOV4小模型:

./darknet detector demo ./cfg/coco.data ./cfg/yolov4-tiny.cfg ./yolov4-tiny.weights /home/caozilong/onnx/FairMOT/videos/MOT16-03.mp4

和大模型相比,小模型检测帧率得到明显提升,但损失了召回率。

和YOLOV3的比较参考:

代码$ git clone https://github.com/pjreddie/darknet$ cd darknet$ makecaozilong@caozilong-Vostro-3268:~/yolo$ git clone https://github.com/pjreddie/darknet正克隆到 'darknet'...remote: Enumerating objects: 5937, done.remote: Total 5937

以上只是对darknet的使用方式和工作方式进行了浅显的测试和使用,具体的技术原理有待更深入的挖掘。

结束!