Python package Detecto released for simple video object detection
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.
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.