Before a model goes to production, you need to build logic around the model. This often involves filtering detections from the model. For instance, you may want to retrieve detections from a model that are above a specified confidence level, or detections in a particular region of an image or video.
Using supervision, you can filter detections from computer vision models in a few lines of code.
supervision is an open-source Python package with a range of utilities for working with computer vision models. For this tutorial, we will focus specifically on filtering detections with supervision, but you can also use supervision for model evaluation, visualizing detections, and more.
Below, we show how to filter
Florence 2
detections with supervision. We will:
1. Install supervision
2. Load
Florence 2
model detections
3. Show how to filter by confidence, area, and more
Without further ado, let's get started!
First, install the supervision pip package:
Once you have installed supervision, you are ready to load your data and start writing logic to filter detections.
supervision has a standard class called supervision.Detections() that provides a range of functions for working with bounding box and segmentation detections.
You can load predictions into a Detections() object in a single line of code using the supervision "from" loaders.
For
Florence 2
predictions, we will use the
from_lmm
data loader:
With supervision, you can filter detections by:
You can combine these filters to build the logic you need.
For this guide, we will focus on filtering by classes and confidence. To learn about the other filters available in supervision, check out the Detections() quickstart guide.
To filter
Florence 2
detections by class, use the following code:
Replace the number 0 with the ID of the class whose predictions you want to retriev.e
To retrieve
Florence 2
detections by class, use the following code:
Where selected_classes contains the list of class IDs you want to filter.
To retrieve
Florence 2
detections over a specified confidence level, use the following code:
supervision provides an extensive range of functionalities for working with computer vision models. With supervision, you can:
1. Process and filter detections and segmentation masks from a range of popular models (YOLOv5, Ultralytics YOLOv8, MMDetection, and more).
2. Process and filter classifications
3. Compute confusion matrices
4. Plot bounding boxes and segmentation masks
And more! To learn about the full range of functionality in supervision, check out the supervision documentation.