Exploring darknet and implementing it.
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.
Darknet
├── build_release
| └── libdarknet.so
|
├── cfg
| └── cifar.data - this is the file we created for training and predicting our models using CIFAR dataset.
| └── CNN.cfg - CNN model cfg file.
| └── coco.data
| └── coco.names
| └── ResNet_34.cfg - ResNet34 model cfg file.
| └── yolov4.cfg - YOLO v4 cfg file.
|
├── data
| └── cifar - after downloading cifar this folder is created.
| └── test - this folder contains images for testing our models.
| └── train - this folder contains images for training our models.
| └── labels.txt - this file contains the labels for image classification.
| └── test.list - this file contains paths to the images in the test folder.
| └── train.list - this file contains paths to the images in the train folder.
|
├── darknet - darknet executable (made after doing make)
|
├── darknet.py - python wrapper for darknet.
|
├── darknet_images.py - python code for object detection in images.
|
├── darknet_video.py - python code for object detection in videos.
|
├── Makefile - special file, containing shell commands. While in the directory containing this makefile, you will type make and the commands in the Makefile will be executed.
|
├── yolov4.weights - downloaded wieghts for training with YOLOv4.
Install python3 (it's preinstalled on ubuntu).
Install pip.
Install cmake using: sudo pip install cmake
git clone https://github.com/AlexeyAB/darknet
cd darknet
mkdir build_release
cd build_release
Follow this.
Install openCV first using:
sudo apt update
sudo apt install libopencv-dev python3-opencv
Then cmake ..-DENABLE_CUDA=OFF
And the final command is make -j4
Our Complete Tutorial for how we trained a 34-layer Resnet Model using Colab is here: How to train a Classifier on Cifar-10 using Darknet on Colab notebook using a Resnet model's config file Following the tutorial, setting up and installation of darknet to acquiring the dataset and writing your own [config file](add link if we explain about config files) to train and test a model can be done in 7 simple steps, and use almost no resources of your native machine!
Using the darknet library we detect objects in images as well as videos. The simple_darknet_code.py does exactly that for images.
| Original Image | Object Detection |
|---|---|
![]() |
![]() |
The CIFAR-10 dataset consists of 60000 32x32 colour images in 10 classes, with 6000 images per class. There are 50000 training images and 10000 test images.
The dataset is divided into five training batches and one test batch, each with 10000 images. The test batch contains exactly 1000 randomly-selected images from each class. The training batches contain the remaining images in random order, but some training batches may contain more images from one class than another. Between them, the training batches contain exactly 5000 images from each class.
We will be using this dataset to train and test our models.
The python, MATLAB, and binary version can be downloaded from this link.
But since we are training through darknet, we will use a mirror of the dataset as we want the pictures in image format. Follow instructions at this link to do so.
Also make the cifar.data file in the cfg folder of the cloned darknet repository from the above, but since we will be using our own config files, we don't need the cifra_small.cfg file from the above link.
After making the cfg files, we are ready to train our models now using the CIFAR-10 dataset!
cd darknet
./darknet classifier train cfg/cifar.data cfg/CNN.cfg
cd darknet
./darknet classifier train cfg/cifar.data cfg/ResNet_34.cfg
After training, we get a .weights file which stores the weights of the model. Using this file we will now predict outputs.
./darknet classifier predict cfg/cifar.data cfg/CNN.cfg backup/CNN_final.weights
./darknet classifier predict cfg/cifar.data cfg/ResNet_34.cfg backup/ResNet_34_final.weights


Average Loss = 4.4057

This model is inspired by the Deep Residual Learning for Image Recognition research paper by Microsoft Research.
Average Loss = 1.7484
- SRA VJTI Eklavya 2021
- pjreddie
- AlexeyAB
- Project Drive
- Speacial thanks to our mentors Aman Chhaparia and Prathamesh Tagore and to the whole SRA Team for guiding us throughout this project.





