1. 程式人生 > >Linux、Windows下試用DarkNet之YoLo CPU物體識別

Linux、Windows下試用DarkNet之YoLo CPU物體識別

關於YOLO:

YOLO——You Only Look Once
Faster RCNN需要對20k個anchor box進行判斷是否是物體,然後再進行物體識別,分成了兩步。 
YOLO(You Only Look Once)則把物體框的選擇與識別進行了結合,一步輸出,即變成”You Only Look Once”。 
所以識別速度非常快,達到每秒45幀,而在快速版YOLO(Fast YOLO,卷積層更少)中,可以達到每秒155幀。

關於DarkNet:

#Darknet#
Darknet is an open source neural network framework written in C and CUDA. It is fast, easy to install, and supports CPU and GPU computation.
For more information see the [Darknet project website](http://pjreddie.com/darknet or https://github.com/pjreddie/darknet).

安裝指南:http://pjreddie.com/darknet/install/

這個是我見過安裝最簡單的開源庫了!!!

linux下,解壓後直接make就可以了,如果你想實時視覺化,開啟OPENCV=1,關於這裡配置OPENCV時需要注意下:

ifeq ($(OPENCV), 1) 
COMMON+= -DOPENCV -I/usr/local/include
CFLAGS+= -DOPENCV
LDFLAGS+= -L/usr/local/lib -lopencv_core -lopencv_highgui -lopencv_imgproc
endif

編譯好後,下載訓練好的權值資料yolo.weights(我下的是700M左右的),同時使用了相應的yolo.cfg,從官網下的沒執行成功!!!

貼一下yolo.cfg

[net]
batch=1
subdivisions=1
height=448
width=448
channels=3
momentum=0.9
decay=0.0005
saturation=1.5
exposure=1.5
hue=.1

learning_rate=0.0005
policy=steps
steps=200,400,600,20000,30000
scales=2.5,2,2,.1,.1
max_batches = 40000

[convolutional]
batch_normalize=1
filters=64
size=7
stride=2
pad=1
activation=leaky

[maxpool]
size=2
stride=2

[convolutional]
batch_normalize=1
filters=192
size=3
stride=1
pad=1
activation=leaky

[maxpool]
size=2
stride=2

[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky

[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky

[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky

[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky

[maxpool]
size=2
stride=2

[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky

[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky

[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky

[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky

[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky

[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky

[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky

[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky

[convolutional]
batch_normalize=1
filters=512
size=1
stride=1
pad=1
activation=leaky

[convolutional]
batch_normalize=1
filters=1024
size=3
stride=1
pad=1
activation=leaky

[maxpool]
size=2
stride=2

[convolutional]
batch_normalize=1
filters=512
size=1
stride=1
pad=1
activation=leaky

[convolutional]
batch_normalize=1
filters=1024
size=3
stride=1
pad=1
activation=leaky

[convolutional]
batch_normalize=1
filters=512
size=1
stride=1
pad=1
activation=leaky

[convolutional]
batch_normalize=1
filters=1024
size=3
stride=1
pad=1
activation=leaky

#######

[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=1024
activation=leaky

[convolutional]
batch_normalize=1
size=3
stride=2
pad=1
filters=1024
activation=leaky

[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=1024
activation=leaky

[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=1024
activation=leaky

[local]
size=3
stride=1
pad=1
filters=256
activation=leaky

[dropout]
probability=.5

[connected]
output= 1715
activation=linear

[detection]
classes=20
coords=4
rescore=1
side=7
num=3
softmax=0
sqrt=1
jitter=.2

object_scale=1
noobject_scale=.5
class_scale=1
coord_scale=5

鍵入命令:

$>./darknet yolo test cfg/yolo.cfg yolo.weights data/dog.jpg




可見CPU下Debug耗時太長啊!