RFBNet: Custom Object Detection training with 6 lines of code
Last Updated on July 20, 2023 by Editorial Team
Author(s): Akula Hemanth Kumar
Originally published on Towards AI.
Making computer vision easy with Monk, low code Deep Learning tool and a unified wrapper for Computer Vision.
In a previous article, we have built a custom object detector using Monkβs RetinaNet. In this article, we will build a Low Altitude Aerial Traffic Surveillance using Monkβs RFBNet, built on top of PyTorch RFBNet.
Letβs get started!!
Table of Contents
- Data Collection
- Convert to COCO format
- Training model
- Testing object detector
Data Collection
In this article, we are using data from Low Altitude Aerial Traffic Surveillance.
Download the data zip file
$ ! wget --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$(wget --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.google.com/uc?export=download&id=1pJ3xfKtHiTdysX5G3dxqKTdGESOBYCxJ' -O- U+007C sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')&id=1pJ3xfKtHiTdysX5G3dxqKTdGESOBYCxJ" -O data.zip && rm -rf /tmp/cookies.txt
Download the annotations zip file
$ ! wget --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$(wget --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.google.com/uc?export=download&id=1boGF0L6olGe_Nu7rd1R8N7YmQErCb0xA' -O- U+007C sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')&id=1boGF0L6olGe_Nu7rd1R8N7YmQErCb0xA" -O annotations.zip && rm -rf /tmp/cookies.txt
Create a dataset directory and push the unzipped data and annotations to the dataset directory.
#Create dataset
$ !mkdir dataset# Unzip data
$ ! unzip -q data.zip
$ ! unzip -q annotations.zip# mov to dataset folder
$ !mv images dataset/
$ !mv annotations.json dataset/
Convert to COCO format
Dataset Directory Structure
./dataset (root_dir)
U+007C
U+007C---------/
U+007C U+007C
U+007C U+007C---images
U+007C U+007C----U+007C
U+007C U+007C-------------------img1.jpg
U+007C U+007C-------------------img2.jpg
U+007C U+007C-------------------.........(and so on)
U+007C
U+007C
U+007C U+007C---annotations
U+007C U+007C----U+007C
U+007C U+007C--------------------annotations.json
Here we Convert to COCO format via Monk format
- Convert from the current format to Monk format
2. Convert from Monk format to COCO format.
Desired annotation COCO Format
./ (root_dir)
U+007C
U+007C------dataset (coco_dir)
U+007C U+007C
U+007C U+007C---images (set_dir)
U+007C U+007C----U+007C
U+007C U+007C-------------------img1.jpg
U+007C U+007C-------------------img2.jpg
U+007C U+007C-------------------.........(and so on)
U+007C
U+007C
U+007C U+007C---annotations
U+007C U+007C----U+007C
U+007C U+007C--------------------instances_images.json
U+007C U+007C--------------------classes.txt
- instances_Train.json -> In proper COCO format
- classes.txt -> A list of classes in alphabetical order
To get classes.txt run
For instances_Images.json run
Training model
Then run the training code as seen below
DONE! The above 6-lines of code is all you need to initiate the training on your custom dataset. Now letβs break down the code to its part:
- In the first line, we import the βDetectorβ class from MonkAI.
- In the 2nd line, we created an instance of the class.
- In the 3rd line, we set the path to our custom dataset. We specified the following parameters:
β batch_size: This is the batch size for the training.
β image_size: Choose the image size
β num_workers: Number of workers used in data loading
- In the 4th line, we specified the following parameters:
β model_name: Choose a base model from βvggβ, βe_vggβ, βmobilenetβ
β use_gpu: Whether to use GPU or not
β ngpu: Number of GPUβs to be used
- In the 5th line, we set the hyperparameters. we specified the following parameters:
β lr: initial learning rate
β momentum: momentum for SGD
β weight_decay: Weight decay for SGD
β gamma: Gamma update for SGD
- In the 6th line, we specify the training parameter, we specified the following parameters:
β epochs: Number of epochs for training
β log_iters: Print the loss at each iteration
β output_weights_dir: Directory to store weights
Testing object detector
we have trained the custom model to detect Low Altitude Aerial Traffic Surveillance. We will use the saved weights file to detect the object in an image.
Some image inferences, you can see:
You can find the complete code on Github. Give us βοΈ on our GitHub repo if you like Monk.
In this experiment, we created a custom object detection using RFBNet with just basic programming skills without even knowing the architecture and PyTorch framework.
For more examples of custom object detection, checkout
Tessellate-Imaging/Monk_Object_Detection
You can't perform that action at this time. You signed in with another tab or window. You signed out in another tab orβ¦
github.com
If you have any questions, you can reach Abhishek and Akash. Feel free to reach out to them.
I am extremely passionate about computer vision and deep learning. I am an open-source contributor to Monk Libraries.
You can also see my other writings at:
Akula Hemanth Kumar – Medium
Read writing from Akula Hemanth Kumar on Medium. Computer vision enthusiast U+007C Linkedinβ¦
medium.com
Join thousands of data leaders on the AI newsletter. Join over 80,000 subscribers and keep up to date with the latest developments in AI. From research to projects and ideas. If you are building an AI startup, an AI-related product, or a service, we invite you to consider becoming aΒ sponsor.
Published via Towards AI