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

Unlock the full potential of AI with Building LLMs for Productionβ€”our 470+ page guide to mastering LLMs with practical projects and expert insights!

Publication

Custom Object Detection using EfficientDet- The Simplest way
Latest   Machine Learning

Custom Object Detection using EfficientDet- The Simplest way

Last Updated on July 20, 2023 by Editorial Team

Author(s): Akula Hemanth Kumar

Originally published on Towards AI.

Object Detection

In this article, I am going to show you how to create your custom object detector using Monk’s EfficientDet.

I am assuming that you already know pretty basics of deep learning computer vision. Before diving into it, make sure you know what’s object detection, what’s transfer learning, and some other deep learning terms.

If you don’t know about all these, It’s time to go back and learn the basics and then come back to this post. Of course, you can do all this stuff without any knowledge using Monk but it’s perfect to have your basics clear. I will put some learning resources in the last section of this post.

Table of contents

  1. Data Gathering
  2. Convert to COCO format
  3. Training model
  4. Testing object detector

Data Gathering

In this article, we are using data from Exclusively-Dark-Image-Dataset.

wget http://web.fsktm.um.edu.my/~cschan/source/CVIU/ExDark.zipwget --no-check-certificate 'https://docs.google.com/uc?export=download&id=1FfEuDUdRbOFTtL8GioPceFghshMvfX7S' -O ExDark_Annno.zip

Convert to COCO format

The current format of downloaded data is

Dataset Directory Structure

Dark (root_dir)
U+007C
U+007C------Images (img_dir)
U+007C U+007C
U+007C U+007C----Bicycle
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-----Boat
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-----...........(and so on)
U+007C
U+007C
U+007C
U+007C------Annotations (anno_dir)
U+007C U+007C
U+007C U+007C----Bicycle
U+007C U+007C
U+007C U+007C---------img1.jpg.txt
U+007C U+007C---------img2.jpg.txt
U+007C U+007C---------..........(and so on)
U+007C
U+007C U+007C-----Boat
U+007C U+007C
U+007C U+007C---------img1.jpg.txt
U+007C U+007C---------img2.jpg.txt
U+007C U+007C---------..........(and so on)
U+007C
U+007C U+007C------............(and so on)

Here we Convert to COCO format via Monk format

  1. Convert from the current format to Monk format

Monk Format

Dataset Directory Structure

Dark (root)
U+007C
U+007C------Images (img_dir)
U+007C U+007C
U+007C U+007C----Bicycle
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-----Boat
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-----...........(and so on)
U+007C
U+007C
U+007C------train_labels.csv (anno_file)

Annotation file format

U+007C Id U+007C Labels U+007C
U+007C img1.jpg U+007C x1 y1 x2 y2 label1 x1 y1 x2 y2 label2 U+007C
  • Labels: xmin ymin xmax ymax label
  • xmin, ymin β€” top left corner of bounding box

COCO Format

Dataset Directory Structure

./ (root_dir)
U+007C
U+007C------Dark (coco_dir)
U+007C
U+007C------Images (set_dir)
U+007C U+007C
U+007C U+007C----Bicycle
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-----Boat
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-----...........(and so on)
U+007C
U+007C
U+007C
U+007C------annotations
U+007C----------U+007C
U+007C--------------------instances_Images.json (instances_<set_dir>.json)
U+007C--------------------classes.txt
  • instances_Train.json -> In proper COCO format
  • classes.txt -> A list of classes in alphabetical order

For TrainSet

  • root_dir = β€œ./”;
  • coco_dir = β€œDark”;
  • img_dir = β€œ./”;
  • set_dir = β€œImages”;

Note: Annotation file name too coincides against the set_dir

Annotations folder contain two files classes.txt, instances_Images.json

2. Convert from Monk format to COCO format.

To get classes.txt run

For instances_Images.json run

Training model

In Training choose the appropriate batch size, learning rate, set path to directories. You can also train on multiple GPUs.For example, if you are using 2 GPU change line8 to gtf.model( gpu_devices=[0,1])

Testing object detector

After training the model, we can get the weights file in the trained folder.

Some of the image inferences you can see below:

Inference 1
Inference 2

You can find the complete code on Github.

If you have any questions, you can reach Abhishek and Akash. Feel free to reach out to them.

β€œThank You”

References and Credit

  1. Paper on EfficientDet
  2. https://github.com/signatrix/efficientdet
  3. EfficientDet Blog
  4. https://medium.com/analytics-vidhya/custom-object-detection-with-yolov3-8f72fe8ced79
Photo by Srilekha

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 ↓