Posted on

Learning Outcomes:

  1. Image Classification with Darknet
  2. Object Detection with Darknet

What is 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. Darknet can let us perform object detection and image classification with very high accuracy and mAP (Mean Average Precision).

For more introduction to Darknet and installation guide, check out my previous article — Darknet — A Neural Network Framework written in C and CUDA.

Image Classification using Pretrained Model

Download the pre-trained classification model here and put it into the Darknet folder. This model is trained based on the CIFAR10 dataset. This dataset consists of 1000 classes (number of objects).

darknet.exe classifier predict cfg/imagenet1k.data cfg/darknet19.cfg darknet19.weights data/dog.jpg

Run the command above using Command Prompt to start the image classification process on dog.jpg.

As you can see, the model predicted malamute (52.15%), Eskimo dog (27.23%), dogsled (2.19%), and bicycle-built-for-two (0.86%) in the image.

You can try with your own image using the command below:

darknet.exe classifier predict cfg/imagenet1k.data cfg/darknet19.cfg darknet19.weights <Image Path>

Object Detection using Darknet YOLOv4

Download the pre-trained YOLOv4 model here and put it into the Darknet folder. This model is trained based on COCO Dataset. This dataset consists of 330k images and 80 object categories.

1. Image

Run the command below on Command Prompt, and see what can be detected in giraffe.jpg.

darknet.exe detector test cfg/coco.data cfg/yolov4.cfg yolov4.weights -thresh 0.25 data/giraffe.jpg

2. Video

Download any video you like. Name it as test.mp4 and put it in the Darknet folder. Then, run the command below to start object detection!

darknet.exe detector demo cfg/coco.data cfg/yolov4.cfg yolov4.weights -ext_output test.mp4

If you want to save the result, use the command as follows.

darknet.exe detector demo cfg/coco.data cfg/yolov4.cfg yolov4.weights -ext_output test.mp4 -out_filename result.mp4

3. Real-Time Detection using Web Camera

Run the command below in Command Prompt. Your web camera will turn on and run detection in real-time. The FPS will depend on how strong your CPUs/GPUs in on your device.

darknet.exe detector demo cfg/coco.data cfg/yolov4.cfg yolov4.weights -c 0

Conclusion

In conclusion, Darknet is a very powerful open-source neural network framework to perform image classification and object detection with very high accuracy, high mAP (Mean Average Precision), and IoU (Intersection over Union).

Besides, YOLO is a very powerful object detection framework with the highest FPS and highest accuracy among all the object detection frameworks. Other than using YOLO pre-trained model to do detection, we can train our own YOLO model using a custom dataset to detect specific objects or use it to perform image classification.

About Author

This article is written by Draden Liang Han Sheng, Junior Artificial Intelligence Engineer in CertifAI, Penang, Malaysia. He has a passion for Deep Learning, Computer Vision and also Edge Devices. He made several AI-based Web/Mobile Applications to help clients solving real-world problems. Feel free to read about him via his portfolio or Github profile.

Leave a Reply

Your email address will not be published.