π Detections
Detections represent bounding box, segmentation, or classification results.
Overview
The Detections
class encapsulates a wide array of detection data. The class can represent bounding box, segmentation, and classification results.
Arguments
Type of detection (DetectionType.BOUNDING_BOX
, DetectionType.SEGMENTATION
, or DetectionType.CLASSIFICATION
).
Coordinates of bounding boxes [x1, y1, x2, y2]
for each detection, where (x1, y1) refers to the top left coordinate and (x2, y2) refers to the bottom right coordinate.
Class IDs for each detection, indexing into classes
.
Array of class names, indexed by class_ids
.
Additional custom data related to detections (Default: empty dictionary).
Segmentation masks for each detection, required for segmentation types.
Confidence scores for each detection.
Examples
Bounding Box Detections
There are two bounding boxes in this bounding box Detections object: the box with coordinates (50, 50) and (100, 100) is of class βcatβ with 90% confidence, and the box with coordinates (150, 150) and (200, 200) is of class βdogβ with 80% confidence.
Classification Detections
A classification detection is created with multiple classifications: βappleβ and βfruitβ.
The resulting Detections object looks like this:
Segmentation Detections
We will support Segmentation detections shortly.
Methods
Splits the Detections
object into a list of Detections
objects, each containing a single detection.
Returns:
List['Detections']
: A list of Detections objects, each containing a single detection.
Creates a Detections
instance from a list of class names
Parameters:
assigned_classes
(List[str]
): The class name(s) that have been assigned to the classification detection.all_classes
(Optional[List[str]]
): List of strings representing all possible class names that can be assigned in the classification detection.
Returns:
Detections
: A classification Detections object.
Creates a Detections
instance from a YOLOv5 inference result.
Parameters:
yolov5_results
(yolov5.models.common.Detections
): The output Detections instance from YOLOv5.
Returns:
Detections
: A bounding box Detections object.
Creates a Detections
instance from an Ultralytics YOLOv8 inference result.
Parameters:
ultralytics_results
(ultralytics.yolo.engine.results.Results
): The output Results instance from YOLOv8.
Returns:
Detections
: A bounding box or segmentation Detections object.
Creates an empty Detections
object.
Returns:
Detections
: An empty bounding box Detections object.
Converts the Detections
instance to a supervision.Detections
instance.
Returns:
sv.Detections
: A supervision Detections instance.
Properties
Returns the list of confidence scores associated with the detections.
Returns a NumPy array containing the area of each detection.
Specifically, if segmentation masks are available, a NumPy array containing the area of each mask is returned. Otherwise, a NumPy array containing the area of each bounding box is returned.
Returns a NumPy array containing the area of each bounding box.
Return the list of class names associated with the detections.
Example
Creating a Detection from YOLOv5
Converting to Supervision
This documentation covers the essential usage of the Detections
class, including creation, manipulation, and conversion of detection data.