Object Detection and Segmentation using Detectron2

Python application for real time object detection and segmentation.

Photo by Cory Schadt on Unsplash

Overview

In previous article I walked through with you on using YOLOv5 for real time object detection. In this article let’s develop a Python application for real time object detection using Detectron2, which is a Facebook AI Research’s next generation software system that implements state-of-the-art object detection algorithms.

The Application

The application uses opencv-python and Detectron2 pre-trained model to capture camera images and try to detect the objects.

  • Git clone the repository.
  • Run python setup.py install
  • Install Detectron2 based on Python version and GPU availability
  • Type d2 to start the application
  • Type q to exit the application
Real Time Object Detection

The Code

OpenCV is used to capture camera images. The application captures camera images in the main process, and spawns a separate process to detect objects in the image frame.

The application should work without GPU, but for better performance you should use a GPU machine.

The image with detected objects will be displayed in a separate frame.

You can find the full listing of the code below.

Detectron2 Resources

Training a Custom Model

You can refer to the Colab notebook on how to train a custom model using your own dataset, e.g. to detecting balloons as provided in the example.

Model Zoo

There is a large collection of baselines trained with Detectron2 available for download.

Command Line Tool

There is also a command line tool for demo purpose.

Projects

You can also check out projects built on Detectron2.

Summary

It is relatively easily to use Detectron2 for object detection, and there are many more features that you can try on this library. Read the documentation to find out more.

You can find the sample application from this repository.

Do also check out the following articles!

Programmer and occasional blogger.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store