16

Object Detection in 6 steps using Detectron2

 3 years ago
source link: https://mc.ai/object-detection-in-6-steps-using-detectron2-2/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

u6j2MfV.png!web

Let’s get started!

Using Detectron 2, Object Detection can be performed on any custom dataset using seven steps. All the steps are readily available in this Google Colab Notebook and you can run it straight away!

Using Google Colab for this would be an easy task as we can use a GPU for faster training.

Step 1: Installing Detectron 2

Kickstart with installing a few dependencies such as Torch Vision and COCO API and check whether CUDA is available. CUDA helps in keeping track of the currently selected GPU . And then install Detectron2.

# install dependencies: 
!pip install -U torch==1.5 torchvision==0.6 -f https://download.pytorch.org/whl/cu101/torch_stable.html
!pip install cython pyyaml==5.1
!pip install -U 'git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI'
import torch, torchvision
print(torch.__version__, torch.cuda.is_available())
!gcc --version
# install detectron2:
!pip install detectron2==0.1.3 -f https://dl.fbaipublicfiles.com/detectron2/wheels/cu101/torch1.5/index.html

Step 2: Prepare and Register the Dataset

Import a few necessary packages.

Datasets that have builtin support in detectron2 are listed in builtin datasets . If you want to use a custom dataset while also reusing detectron2’s data loaders, you will need to Register your dataset (i.e., tell detectron2 how to obtain your dataset).

We use our Text Detection Dataset which has three classes:

  1. English
  2. Hindi
  3. Others

We’ll train a text detection model from an existing model pre-trained on the COCO dataset, available in detectron2’s model zoo.

If you’re interested to know the conversion from the raw format of the dataset to the format that Detectron 2 accepts, checkout this Colab Notebook .

There are certain formats in how data can be fed to a model such as a YOLO format, PASCAL VOC format, COCO format, etc. Detectron2 accepts the COCO Format of the dataset. COCO format of the dataset consists of a JSON file which includes all the details of an image such as size, annotations (i.e., bounding box coordinates), labels corresponding to it’s bounding box, etc. For example,

Detectron 2’s format of Dataset

This is how the JSON looks like for one image. There are different types of formats for the bounding box representation. It must be a member of structures.BoxMode for Detectron2. There are 5 such formats. But currently, it supports BoxMode.XYXY_ABS, BoxMode.XYWH_ABS . We use the second format. The (X, Y) represents one coordinate of the bounding box, and W, H represents Width and Height of that box. The category_id refers to the class the box belongs to.

Then, we need to register our dataset.

To verify the data loading is correct, let’s visualize the annotations of randomly selected samples in the training set.

Step 3: Visualize the Training Set

We’ll randomly pick 3 pictures from the train folder of our dataset and see how the bounding boxes look like.

The output looks in this way,

Post navigation

← Predicting Interest Rate with Classification Models — Part 1

চলো যন্ত্রকে ফুল চেনাই →

Request for deletion

About

MC.AI – Aggregated news about artificial intelligence

MC.AI collects interesting articles and news about artificial intelligence and related areas. The contributions come from various open sources and are presented here in a collected form.

The copyrights are held by the original authors, the source is indicated with each contribution.

Contributions which should be deleted from this platform can be reported using the appropriate form (within the contribution).

MC.AI is open for direct submissions, we look forward to your contribution!

Search on MC.AI

mc.ai aggregates articles from different sources - copyright remains at original authors


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK