Darknet: Open Source Neural Networks in C - Classifying With darknet19.weights Models
Darknet: Open Source Neural Networks in C - Classifying With darknet19.weights Models
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. You can find the source on GitHub
or you can read more about what Darknet can do right here:
ImageNet Classification
https://pjreddie.com/darknet/imagenet/
Classify images with popular models like ResNet and ResNeXt.
You can use Darknet to classify images for the 1000-class ImageNet challenge
. If you haven’t installed Darknet yet, you should do that first
.
http://image-net.org/challenges/LSVRC/2015/index
https://pjreddie.com/darknet/install/
Classifying With Pre-Trained Models
Here are the commands to install Darknet, download a classification weights file, and run a classifier on an image:
git clone https://github.com/pjreddie/darknet.git cd darknet make wget https://pjreddie.com/media/files/darknet19.weights ./darknet classifier predict cfg/imagenet1k.data cfg/darknet19.cfg darknet19.weights data/dog.jpg
[email protected]:~/eclipse-darknet/darknet_models$ wget https://pjreddie.com/media/files/darknet19.weights
--2018-11-07 19:51:53-- https://pjreddie.com/media/files/darknet19.weights
Resolving pjreddie.com (pjreddie.com)... 128.208.3.39
Connecting to pjreddie.com (pjreddie.com)|128.208.3.39|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 83427120 (80M) [application/octet-stream]
Saving to: ‘darknet19.weights’
darknet19.weights 100%[===========================================>] 79.56M 3.49MB/s in 26s
2018-11-07 19:52:20 (3.08 MB/s) - ‘darknet19.weights’ saved [83427120/83427120]
[email protected]:~/eclipse-darknet/darknet_models$
This example uses the Darknet19 model, you can read more about it below. After running this command you should see the following output:
layer filters size input output
0 conv 32 3 x 3 / 1 256 x 256 x 3 -> 256 x 256 x 32 0.113 BFLOPs
1 max 2 x 2 / 2 256 x 256 x 32 -> 128 x 128 x 32
2 conv 64 3 x 3 / 1 128 x 128 x 32 -> 128 x 128 x 64 0.604 BFLOPs
3 max 2 x 2 / 2 128 x 128 x 64 -> 64 x 64 x 64
4 conv 128 3 x 3 / 1 64 x 64 x 64 -> 64 x 64 x 128 0.604 BFLOPs
5 conv 64 1 x 1 / 1 64 x 64 x 128 -> 64 x 64 x 64 0.067 BFLOPs
6 conv 128 3 x 3 / 1 64 x 64 x 64 -> 64 x 64 x 128 0.604 BFLOPs
7 max 2 x 2 / 2 64 x 64 x 128 -> 32 x 32 x 128
8 conv 256 3 x 3 / 1 32 x 32 x 128 -> 32 x 32 x 256 0.604 BFLOPs
9 conv 128 1 x 1 / 1 32 x 32 x 256 -> 32 x 32 x 128 0.067 BFLOPs
10 conv 256 3 x 3 / 1 32 x 32 x 128 -> 32 x 32 x 256 0.604 BFLOPs
11 max 2 x 2 / 2 32 x 32 x 256 -> 16 x 16 x 256
12 conv 512 3 x 3 / 1 16 x 16 x 256 -> 16 x 16 x 512 0.604 BFLOPs
13 conv 256 1 x 1 / 1 16 x 16 x 512 -> 16 x 16 x 256 0.067 BFLOPs
14 conv 512 3 x 3 / 1 16 x 16 x 256 -> 16 x 16 x 512 0.604 BFLOPs
15 conv 256 1 x 1 / 1 16 x 16 x 512 -> 16 x 16 x 256 0.067 BFLOPs
16 conv 512 3 x 3 / 1 16 x 16 x 256 -> 16 x 16 x 512 0.604 BFLOPs
17 max 2 x 2 / 2 16 x 16 x 512 -> 8 x 8 x 512
18 conv 1024 3 x 3 / 1 8 x 8 x 512 -> 8 x 8 x1024 0.604 BFLOPs
19 conv 512 1 x 1 / 1 8 x 8 x1024 -> 8 x 8 x 512 0.067 BFLOPs
20 conv 1024 3 x 3 / 1 8 x 8 x 512 -> 8 x 8 x1024 0.604 BFLOPs
21 conv 512 1 x 1 / 1 8 x 8 x1024 -> 8 x 8 x 512 0.067 BFLOPs
22 conv 1024 3 x 3 / 1 8 x 8 x 512 -> 8 x 8 x1024 0.604 BFLOPs
23 conv 1000 1 x 1 / 1 8 x 8 x1024 -> 8 x 8 x1000 0.131 BFLOPs
24 avg 8 x 8 x1000 -> 1000
25 softmax 1000
Loading weights from darknet19.weights...Done!
data/dog.jpg: Predicted in 0.769246 seconds.
42.55%: malamute
22.93%: Eskimo dog
12.51%: Siberian husky
2.76%: bicycle-built-for-two
1.20%: mountain bike
malamute ['mæləmjuːt]:n. 北極狗,愛斯基摩狗
Eskimo dog:愛斯基摩狗,北極雪橇狗
Siberian husky:西伯利亞愛斯基摩狗
mountain bike:n. 山地車,山地自行車
Darknet displays information as it loads the config file and weights, then it classifies the image and prints the top-10 classes for the image. Kelp is a mixed breed dog but she has a lot of malamute in her so we’ll consider this a success!
kelp [kelp]:n. 巨藻,海藻,海草灰 vi. 燒製海草灰
You can also try with other images, like the bald eagle image:
./darknet classifier predict cfg/imagenet1k.data cfg/darknet19.cfg darknet19.weights data/eagle.jpg
Which produces:
...
data/eagle.jpg: Predicted in 0.707070 seconds.
84.68%: bald eagle
11.91%: kite
2.62%: vulture
0.08%: great grey owl
0.07%: hen
bald eagle:禿鷹 (美國的國鳥),比喻禿頭的政治家
vulture ['vʌltʃə]:n. 禿鷹,禿鷲,貪婪的人
owl [aʊl]:n. 貓頭鷹,梟,慣於晚上活動的人
hen [hen]:n. 母雞,女人,雌禽
Pretty good!
If you don’t specify an image file you will be prompted at run-time for an image. This way you can classify multiple in a row without reloading the whole model. Use the command:
./darknet classifier predict cfg/imagenet1k.data cfg/darknet19.cfg darknet19.weights
Then you will get a prompt that looks like:
....
25: Softmax Layer: 1000 inputs
Loading weights from darknet19.weights...Done!
Enter Image Path:
Whenever you get bored of classifying images you can use Ctrl-C
to exit the program.
1. Makefile
GPU=1
CUDNN=1
OPENCV=0
OPENMP=0
DEBUG=0
2. Program Arguments
right-click on the darknet_181107 -> Properties -> Run/Debug Settings -> New -> C/C++ Application -> OK
/home/strong/eclipse-darknet/darknet_models/darknet19.weights
terminal
./darknet classifier predict cfg/imagenet1k.data cfg/darknet19.cfg darknet19.weights data/dog.jpg
argument
classifier predict cfg/imagenet1k.data cfg/darknet19.cfg /home/strong/eclipse-darknet/darknet_models/darknet19.weights data/dog.jpg
Run darknet_181107-darknet19
right-click on the darknet_181107 -> Properties -> Run As -> Run Configurations…
Run
layer filters size input output
0 conv 32 3 x 3 / 1 256 x 256 x 3 -> 256 x 256 x 32 0.113 BFLOPs
1 max 2 x 2 / 2 256 x 256 x 32 -> 128 x 128 x 32
2 conv 64 3 x 3 / 1 128 x 128 x 32 -> 128 x 128 x 64 0.604 BFLOPs
3 max 2 x 2 / 2 128 x 128 x 64 -> 64 x 64 x 64
4 conv 128 3 x 3 / 1 64 x 64 x 64 -> 64 x 64 x 128 0.604 BFLOPs
5 conv 64 1 x 1 / 1 64 x 64 x 128 -> 64 x 64 x 64 0.067 BFLOPs
6 conv 128 3 x 3 / 1 64 x 64 x 64 -> 64 x 64 x 128 0.604 BFLOPs
7 max 2 x 2 / 2 64 x 64 x 128 -> 32 x 32 x 128
8 conv 256 3 x 3 / 1 32 x 32 x 128 -> 32 x 32 x 256 0.604 BFLOPs
9 conv 128 1 x 1 / 1 32 x 32 x 256 -> 32 x 32 x 128 0.067 BFLOPs
10 conv 256 3 x 3 / 1 32 x 32 x 128 -> 32 x 32 x 256 0.604 BFLOPs
11 max 2 x 2 / 2 32 x 32 x 256 -> 16 x 16 x 256
12 conv 512 3 x 3 / 1 16 x 16 x 256 -> 16 x 16 x 512 0.604 BFLOPs
13 conv 256 1 x 1 / 1 16 x 16 x 512 -> 16 x 16 x 256 0.067 BFLOPs
14 conv 512 3 x 3 / 1 16 x 16 x 256 -> 16 x 16 x 512 0.604 BFLOPs
15 conv 256 1 x 1 / 1 16 x 16 x 512 -> 16 x 16 x 256 0.067 BFLOPs
16 conv 512 3 x 3 / 1 16 x 16 x 256 -> 16 x 16 x 512 0.604 BFLOPs
17 max 2 x 2 / 2 16 x 16 x 512 -> 8 x 8 x 512
18 conv 1024 3 x 3 / 1 8 x 8 x 512 -> 8 x 8 x1024 0.604 BFLOPs
19 conv 512 1 x 1 / 1 8 x 8 x1024 -> 8 x 8 x 512 0.067 BFLOPs
20 conv 1024 3 x 3 / 1 8 x 8 x 512 -> 8 x 8 x1024 0.604 BFLOPs
21 conv 512 1 x 1 / 1 8 x 8 x1024 -> 8 x 8 x 512 0.067 BFLOPs
22 conv 1024 3 x 3 / 1 8 x 8 x 512 -> 8 x 8 x1024 0.604 BFLOPs
23 conv 1000 1 x 1 / 1 8 x 8 x1024 -> 8 x 8 x1000 0.131 BFLOPs
24 avg 8 x 8 x1000 -> 1000
25 softmax 1000
Loading weights from /home/strong/eclipse-darknet/darknet_models/darknet19.weights...Done!
data/dog.jpg: Predicted in 0.005434 seconds.
42.07%: malamute
23.15%: Eskimo dog
12.66%: Siberian husky
2.79%: bicycle-built-for-two
1.20%: mountain bike
Wordbook
you only look once,YOLO
Visual Object Classes,VOC
Pattern Analysis, Statistical Modelling and Computational Learning,PASCAL
mean Average Precision,mAP:平均精度均值
floating point operations per second,FLOPS
frame rate or frame frequency, frames per second,FPS
hertz,Hz
billion,Bn
operations,Ops
configuration,cfg
ImageNet Large Scale Visual Recognition Challenge,ILSVRC
Microsoft Common Objects in Context,MS COCO