module documentation

Intersection over union (IoU) utilities.

Copyright 2017-2025, Voxel51, Inc.

Function compute_bbox_iou Computes the IoU between the given ground truth and predicted detections.
Function compute_ious Computes the pairwise IoUs between the predicted and ground truth objects.
Function compute_max_ious Populates an attribute on each label in the given spatial field(s) that records the max IoU between the object and another object in the same sample/frame.
Function compute_segment_ious Computes the pairwise IoUs between the predicted and ground truth temporal detections.
Function find_duplicates Returns IDs of duplicate labels in the given field of the collection, as defined as labels with an IoU greater than a chosen threshold with another label in the field.
Variable sg Undocumented
Variable so Undocumented
Function _compute_bbox_ious Undocumented
Function _compute_keypoint_similarities Undocumented
Function _compute_mask_ious Undocumented
Function _compute_max_ious Undocumented
Function _compute_object_keypoint_similarity Undocumented
Function _compute_polygon_ious Undocumented
Function _compute_polyline_similarities Undocumented
Function _compute_segment_ious Undocumented
Function _extract_max_ious Undocumented
Function _find_duplicates Undocumented
Function _find_duplicates_greedy Undocumented
Function _find_duplicates_simple Undocumented
Function _get_bbox_dim Undocumented
Function _get_detection_box Undocumented
Function _get_labels Undocumented
Function _get_poly_box Undocumented
Function _masks_to_polylines Undocumented
Function _polylines_to_detections Undocumented
Function _polylines_to_shapely Undocumented
def compute_bbox_iou(gt, pred, gt_crowd=False): (source)

Computes the IoU between the given ground truth and predicted detections.

Parameters
gta fiftyone.core.labels.Detection
preda fiftyone.core.labels.Detection
gt_crowd:Falsewhether the ground truth object is a crowd
Returns
the IoU, in [0, 1]
def compute_ious(preds, gts, iscrowd=None, classwise=False, use_masks=False, use_boxes=False, tolerance=None, sparse=False, error_level=1): (source)

Computes the pairwise IoUs between the predicted and ground truth objects.

For polylines, IoUs are computed as solid shapes when filled=True` and "IoUs" are computed using `object keypoint similarity <https://cocodataset.org/#keypoints-eval>`_ when ``filled=False.

For keypoints, "IoUs" are computed via object keypoint similarity.

Parameters
predsa list of predicted fiftyone.core.labels.Detection, fiftyone.core.labels.Polyline, or fiftyone.core.labels.Keypoints instances
gtsa list of ground truth fiftyone.core.labels.Detection, fiftyone.core.labels.Polyline, or fiftyone.core.labels.Keypoints instances
iscrowd:Nonean optional name of a boolean attribute or boolean function to apply to each label that determines whether a ground truth object is a crowd. If provided, the area of the predicted object is used as the "union" area for IoU calculations involving crowd objects
classwise:Falsewhether to consider objects with different label values as always non-overlapping (True) or to compute IoUs for all objects regardless of label (False)
use_masks:Falsewhether to compute IoUs using the instances masks in the mask attribute of the provided objects, which must be fiftyone.core.labels.Detection instances
use_boxes:Falsewhether to compute IoUs using the bounding boxes of the provided fiftyone.core.labels.Polyline instances rather than using their actual geometries
tolerance:Nonea tolerance, in pixels, when generating approximate polylines for instance masks. Typical values are 1-3 pixels
sparse:Falsewhether to return a sparse dict of non-zero IoUs rather than a full matrix
error_level:1

the error level to use when manipulating instance masks or polylines. Valid values are:

  • 0: raise geometric errors that are encountered
  • 1: log warnings if geometric errors are encountered
  • 2: ignore geometric errors

If error_level > 0, any calculation that raises a geometric error will default to an IoU of 0

Returns
a num_preds x num_gts array of IoUs when sparse=False, or a dict of the form d[pred.id] = [(gt.id, iou), ...] when sparse=True
def compute_max_ious(sample_collection, label_field, other_field=None, iou_attr='max_iou', id_attr=None, progress=None, **kwargs): (source)

Populates an attribute on each label in the given spatial field(s) that records the max IoU between the object and another object in the same sample/frame.

If other_field is provided, IoUs are computed between objects in label_field and other_field.

If no other_field is provided, IoUs are computed between objects in label_field alone, excluding the object itself.

Parameters
sample_collectiona fiftyone.core.collections.SampleCollection
label_fielda label field of type fiftyone.core.labels.Detections, fiftyone.core.labels.Polylines, or fiftyone.core.labels.Keypoints
other_field:Noneanother label field of type fiftyone.core.labels.Detections, fiftyone.core.labels.Polylines, or fiftyone.core.labels.Keypoints
iou_attr:"max_iou"the label attribute in which to store the max IoU
id_attr:Nonean optional attribute in which to store the label ID of the maximum overlapping label
progress:Nonewhether to render a progress bar (True/False), use the default value fiftyone.config.show_progress_bars (None), or a progress callback function to invoke instead
**kwargsoptional keyword arguments for compute_ious
def compute_segment_ious(preds, gts, sparse=False): (source)

Computes the pairwise IoUs between the predicted and ground truth temporal detections.

Parameters
predsa list of predicted fiftyone.core.labels.TemporalDetection instances
gtsa list of ground truth fiftyone.core.labels.TemporalDetection instances
sparse:Falsewhether to return a sparse dict of non-zero IoUs rather than a full matrix
Returns
a num_preds x num_gts array of segment IoUs when sparse=False, or a dict of the form d[pred.id] = [(gt.id, iou), ...] when sparse=True
def find_duplicates(sample_collection, label_field, iou_thresh=0.999, method='simple', progress=None, **kwargs): (source)

Returns IDs of duplicate labels in the given field of the collection, as defined as labels with an IoU greater than a chosen threshold with another label in the field.

The following duplicate removal methods are supported:

  • method="simple": mark the latter label in every pair of labels whose IoU exceeds the threshold. This may remove more labels than the greedy method
  • method="greedy": apply a greedy method to mark the fewest number of labels as duplicate such that no non-duplicate labels have IoU greater than the specified threshold. This method is more computationally expensive than the simple method
Parameters
sample_collectiona fiftyone.core.collections.SampleCollection
label_fielda label field of type fiftyone.core.labels.Detections, fiftyone.core.labels.Polylines, or fiftyone.core.labels.Keypoints
iou_thresh:0.999the IoU threshold to use to determine whether labels are duplicates
method:"simple"the duplicate removal method to use. The supported values are ("simple", "greedy")
progress:Nonewhether to render a progress bar (True/False), use the default value fiftyone.config.show_progress_bars (None), or a progress callback function to invoke instead
**kwargsoptional keyword arguments for compute_ious
Returns
a list of IDs of duplicate labels

Undocumented

Undocumented

def _compute_bbox_ious(preds, gts, iscrowd=None, classwise=False, sparse=False): (source)

Undocumented

def _compute_keypoint_similarities(preds, gts, classwise=False, sparse=False): (source)

Undocumented

def _compute_mask_ious(preds, gts, tolerance, error_level, iscrowd=None, classwise=False, sparse=False): (source)

Undocumented

def _compute_max_ious(doc, field1, field2, **kwargs): (source)

Undocumented

def _compute_object_keypoint_similarity(gtp, predp): (source)

Undocumented

def _compute_polygon_ious(preds, gts, error_level, iscrowd=None, classwise=False, gt_crowds=None, sparse=False): (source)

Undocumented

def _compute_polyline_similarities(preds, gts, classwise=False, sparse=False): (source)

Undocumented

def _compute_segment_ious(preds, gts, sparse=False): (source)

Undocumented

def _extract_max_ious(ious, labels1, labels2): (source)

Undocumented

def _find_duplicates(doc, field, iou_thresh, method, **kwargs): (source)

Undocumented

def _find_duplicates_greedy(ious, iou_thresh): (source)

Undocumented

def _find_duplicates_simple(ious, iou_thresh): (source)

Undocumented

def _get_bbox_dim(detection): (source)

Undocumented

def _get_detection_box(det, dimension=None): (source)

Undocumented

def _get_labels(doc, field): (source)

Undocumented

def _get_poly_box(x): (source)

Undocumented

def _masks_to_polylines(detections, tolerance, error_level): (source)

Undocumented

def _polylines_to_detections(polylines): (source)

Undocumented

def _polylines_to_shapely(polylines, error_level): (source)

Undocumented