Darknet: Open Source Neural Networks in C - Classifying With darknet19.weights Models

Darknet: Open Source Neural Networks in C - Classifying With darknet19.weights Models

https://github.com/pjreddie/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. You can find the source on GitHub or you can read more about what Darknet can do right here:

1. 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/

1.1. 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
strong@foreverstrong:~/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]

strong@foreverstrong:~/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:
https://pjreddie.com/darknet/imagenet/#darknet19

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

References

[1] Yongqiang Cheng, https://yongqiang.blog.csdn.net/

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Yongqiang Cheng

梦想不是浮躁,而是沉淀和积累。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值