days
0
-13
-9
hours
-1
-3
minutes
0
-8
seconds
-3
-6
search
Detect objects with detecto

Python package Detecto released for simple video object detection

Maika Möbus
© Shutterstock / studiostoks

Detecto is neither the name of a new superhero nor a detective novel, but a recently developed Python package for training and running object detection models. Built on top of PyTorch, it is designed to be easy to use—and its developer claims that under ten lines of code are enough to run the trained machine learning models on videos.

The open source Python package Detecto has been released for the machine learning task of object detection. It is built on top of PyTorch and allows you to first train your machine learning models and then run them on a video. Let’s see what features Detecto offers, what requirements the package has and how to use it.

SEE ALSO: PyTorch 1.4 adds experimental Java bindings and additional PyTorch Mobile support

Object detection with Detecto

The first step is to install Detecto via pip: pip install detecto.

In order to use the package, you need a labeled image dataset with an individual XML file for each image. The files must then be converted into a CSV file. Custom transformations are possible if you make sure to convert the images to torch.Tensors and normalize them. Then, you can train your object detection model with Detecto as described in the quickstart guide.

Once the training has been completed, under ten lines of code should allow you to run object detection on a video, as demonstrated in this example on GitHub:

from detecto.core import Model, Dataset, DataLoader

from detecto.utils import xml_to_csv

from detecto.visualize import detect_video

 

xml_to_csv('xml_labels/', 'labels.csv')

dataset = Dataset('labels.csv', 'images/')

loader = DataLoader(dataset)

 

model = Model(['dog', 'cat', 'rabbit'])

model.fit(loader)

 

detect_video(model, 'input_video.mp4', 'output_video.avi')


This demo gif shows what Detecto looks like when applied to a video:

Running Detecto on Google Colab

Detecto runs heavy-duty code on the GPU, when available, and otherwise on the CPU. The online service Google Colab can therefore come in handy if you don’t have a GPU. To get you started with Detecto on Google Colab, you can check out the demo.

SEE ALSO: Predicting 2020 and beyond: Real time is out, predicting the future is in

See the GitHub repo and the official docs for further details on Detecto.

Author
Maika Möbus
Maika Möbus has been an editor for Software & Support Media since January 2019. She studied Sociology at Goethe University Frankfurt and Johannes Gutenberg University Mainz.

Leave a Reply