Master LLMs with our FREE course in collaboration with Activeloop & Intel Disruptor Initiative. Join now!

Publication

RFBNet: Custom Object Detection training with 6 lines of code
Latest   Machine Learning

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

  1. Data Collection
  2. Convert to COCO format
  3. Training model
  4. 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

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

Inference 1
Inference 2
Inference 3
Inference 4

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

Photo by Robert Bye on Unsplash

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

Feedback ↓