Name: Towards AI Legal Name: Towards AI, Inc. Description: Towards AI is the world's leading artificial intelligence (AI) and technology publication. Read by thought-leaders and decision-makers around the world. Phone Number: +1-650-246-9381 Email: [email protected]
228 Park Avenue South New York, NY 10003 United States
Website: Publisher: https://towardsai.net/#publisher Diversity Policy: https://towardsai.net/about Ethics Policy: https://towardsai.net/about Masthead: https://towardsai.net/about
Name: Towards AI Legal Name: Towards AI, Inc. Description: Towards AI is the world's leading artificial intelligence (AI) and technology publication. Founders: Roberto Iriondo, , Job Title: Co-founder and Advisor Works for: Towards AI, Inc. Follow Roberto: X, LinkedIn, GitHub, Google Scholar, Towards AI Profile, Medium, ML@CMU, FreeCodeCamp, Crunchbase, Bloomberg, Roberto Iriondo, Generative AI Lab, Generative AI Lab Denis Piffaretti, Job Title: Co-founder Works for: Towards AI, Inc. Louie Peters, Job Title: Co-founder Works for: Towards AI, Inc. Louis-François Bouchard, Job Title: Co-founder Works for: Towards AI, Inc. Cover:
Towards AI Cover
Logo:
Towards AI Logo
Areas Served: Worldwide Alternate Name: Towards AI, Inc. Alternate Name: Towards AI Co. Alternate Name: towards ai Alternate Name: towardsai Alternate Name: towards.ai Alternate Name: tai Alternate Name: toward ai Alternate Name: toward.ai Alternate Name: Towards AI, Inc. Alternate Name: towardsai.net Alternate Name: pub.towardsai.net
5 stars – based on 497 reviews

Frequently Used, Contextual References

TODO: Remember to copy unique IDs whenever it needs used. i.e., URL: 304b2e42315e

Resources

Take our 85+ lesson From Beginner to Advanced LLM Developer Certification: From choosing a project to deploying a working product this is the most comprehensive and practical LLM course out there!

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 ↓