Object Detection#

Run on Google Colab View source on GitHub Download notebook


In this tutorial, we present how to use YOLO models in EvaDB to detect objects. In particular, we focus on detecting objects from the challenging, real-world UA-DETRAC dataset. EvaDB makes it easy to do object detection using its built-in support for YOLO models.

In this tutorial, besides detecting objects, we will also showcase a query where the model’s output is used to retrieve a subset of frames with pedestrian and car objects.


To follow along, you will need to set up a local instance of EvaDB via pip.

Connect to EvaDB#

After installing EvaDB, use the following Python code to establish a connection and obtain a cursor for running EvaQL queries.

import evadb
cursor = evadb.connect().cursor()

We will assume that the input UA-DETRAC video is loaded into EvaDB. To download the video and load it into EvaDB, see the complete object detection notebook on Colab.

Create Object Detection Function#

To create a custom Yolo function based on the popular YOLO-v8m model, use the CREATE FUNCTION statement. In this query, we leverage EvaDB’s built-in support for ultralytics models. We only need to specify the model parameter in the query to create this function:

TYPE  ultralytics
MODEL 'yolov8m.pt';

Object Detection Queries#

After the function is registered in EvaDB, you can use it subsequent SQL queries in different ways.

In the following query, we call the object detector on every image in the video. The output of the function is stored in the label column (i.e., the digit associated with the given frame) of the output DataFrame.

SELECT id, Yolo(data)
FROM ObjectDetectionVideos
WHERE id < 20

This query returns the label of all the images:

| objectdetectionvideos.id              | yolo.labels                                                |
| 0                        | [car, car, car, car, car, car, person, car, ...             |
| 1                        | [car, car, car, car, car, car, car, car, car, ...             |

Filtering Based on YOLO Function#

In the following query, we use the output of the object detector to retrieve a subset of frames that contain a pedestrian and a car.

    FROM ObjectDetectionVideos
    WHERE ['pedestrian', 'car'] <@ Yolo(data).label;

Now, the DataFrame only contains frames with the desired objects:

|  objectdetectionvideos.label |
|                            6 |
|                            6 |

What’s Next?#

👋 EvaDB’s vision is to bring AI inside your database system and make it easy to build fast AI-powered apps. If you liked this tutorial and are excited about our vision, show some ❤️ by: