Yolo-Darknet的安装和使用

1. Yolo-Darknet介绍

YOLO是基于深度学习方法的端到端实时目标检测系统,目前有三个版本,Yolo-v1,Yolo-9000,Yolo-v2。Darknet是Yolo的实现,但Darknet不仅包含Yolo的实现,还包括其它内容。

2. Darknet安装

安装过程如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 代码下载
git clone https://github.com/pjreddie/darknet.git
# 修改Makefile
cd darknet
sed -i '1s/GPU=0/GPU=1/' Makefile
sed -i '2s/CUDNN=0/CUDNN=1/' Makefile
sed -i '3s/OPENCV=0/OPENCV=1/' Makefile
# 安装
make
# 下载预训练的模型
wget https://pjreddie.com/media/files/yolo.weights
wget https://pjreddie.com/media/files/tiny-yolo-voc.weights
wget http://pjreddie.com/media/files/yolov1.weights
wget http://pjreddie.com/media/files/tiny-yolo.weights
wget http://pjreddie.com/media/files/tiny-coco.weights
wget http://pjreddie.com/media/files/yolo-coco.weights

3. Yolo-v2用法

  • 使用预训练的模型进行目标检测
1
./darknet detect cfg/yolo.cfg yolo.weights data/dog.jpg

Result

  • 输入图像名称进行检测
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
$ ./darknet detect cfg/yolo.cfg yolo.weights
# 输入 data/horses.jpg
# 执行结果如下:
layer filters size input output
0 conv 32 3 x 3 / 1 608 x 608 x 3 -> 608 x 608 x 32
1 max 2 x 2 / 2 608 x 608 x 32 -> 304 x 304 x 32
2 conv 64 3 x 3 / 1 304 x 304 x 32 -> 304 x 304 x 64
3 max 2 x 2 / 2 304 x 304 x 64 -> 152 x 152 x 64
4 conv 128 3 x 3 / 1 152 x 152 x 64 -> 152 x 152 x 128
5 conv 64 1 x 1 / 1 152 x 152 x 128 -> 152 x 152 x 64
6 conv 128 3 x 3 / 1 152 x 152 x 64 -> 152 x 152 x 128
7 max 2 x 2 / 2 152 x 152 x 128 -> 76 x 76 x 128
8 conv 256 3 x 3 / 1 76 x 76 x 128 -> 76 x 76 x 256
9 conv 128 1 x 1 / 1 76 x 76 x 256 -> 76 x 76 x 128
10 conv 256 3 x 3 / 1 76 x 76 x 128 -> 76 x 76 x 256
11 max 2 x 2 / 2 76 x 76 x 256 -> 38 x 38 x 256
12 conv 512 3 x 3 / 1 38 x 38 x 256 -> 38 x 38 x 512
13 conv 256 1 x 1 / 1 38 x 38 x 512 -> 38 x 38 x 256
14 conv 512 3 x 3 / 1 38 x 38 x 256 -> 38 x 38 x 512
15 conv 256 1 x 1 / 1 38 x 38 x 512 -> 38 x 38 x 256
16 conv 512 3 x 3 / 1 38 x 38 x 256 -> 38 x 38 x 512
17 max 2 x 2 / 2 38 x 38 x 512 -> 19 x 19 x 512
18 conv 1024 3 x 3 / 1 19 x 19 x 512 -> 19 x 19 x1024
19 conv 512 1 x 1 / 1 19 x 19 x1024 -> 19 x 19 x 512
20 conv 1024 3 x 3 / 1 19 x 19 x 512 -> 19 x 19 x1024
21 conv 512 1 x 1 / 1 19 x 19 x1024 -> 19 x 19 x 512
22 conv 1024 3 x 3 / 1 19 x 19 x 512 -> 19 x 19 x1024
23 conv 1024 3 x 3 / 1 19 x 19 x1024 -> 19 x 19 x1024
24 conv 1024 3 x 3 / 1 19 x 19 x1024 -> 19 x 19 x1024
25 route 16
26 conv 64 1 x 1 / 1 38 x 38 x 512 -> 38 x 38 x 64
27 reorg / 2 38 x 38 x 64 -> 19 x 19 x 256
28 route 27 24
29 conv 1024 3 x 3 / 1 19 x 19 x1280 -> 19 x 19 x1024
30 conv 425 1 x 1 / 1 19 x 19 x1024 -> 19 x 19 x 425
31 detection
mask_scale: Using default '1.000000'
Loading weights from yolo.weights...Done!
Enter Image Path: data/horses.jpg
data/horses.jpg: Predicted in 0.030211 seconds.
horse: 46%
horse: 59%
horse: 91%
(predictions:31): Gtk-WARNING **: cannot open display:

result

  • 设置检测阈值
1
$ ./darknet detect cfg/yolo.cfg yolo.weights data/dog.jpg -thresh 0.1

result

  • 检测视频
1
$ ./darknet detector demo cfg/coco.data cfg/yolo.cfg yolo.weights <video file>

参考资料

  1. https://pjreddie.com/darknet/install/

  2. https://pjreddie.com/darknet/yolo/

  3. https://pjreddie.com/darknet/yolov1/

坚持技术分享,如果觉得有收获就打赏吧!