def compute_ious(
    preds,
    gts,
    iscrowd=None,
    classwise=False,
    use_masks=False,
    use_boxes=False,
    tolerance=None,
    sparse=False,
    error_level=1,
):
    """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 <https://cocodataset.org/#keypoints-eval>`_.

    Args:
        preds: a list of predicted
            :class:`fiftyone.core.labels.Detection`,
            :class:`fiftyone.core.labels.Polyline`, or
            :class:`fiftyone.core.labels.Keypoints` instances
        gts: a list of ground truth
            :class:`fiftyone.core.labels.Detection`,
            :class:`fiftyone.core.labels.Polyline`, or
            :class:`fiftyone.core.labels.Keypoints` instances
        iscrowd (None): an 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 (False): whether 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 (False): whether to compute IoUs using the instances masks in
            the ``mask`` attribute of the provided objects, which must be
            :class:`fiftyone.core.labels.Detection` instances
        use_boxes (False): whether to compute IoUs using the bounding boxes
            of the provided :class:`fiftyone.core.labels.Polyline` instances
            rather than using their actual geometries
        tolerance (None): a tolerance, in pixels, when generating approximate
            polylines for instance masks. Typical values are 1-3 pixels. By
            default, IoUs are computed directly on the dense pixel masks
        sparse (False): whether 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``
    """
    if not preds or not gts:
        if sparse:
            return {p.id: [] for p in preds} if preds else {}
        else:
            return np.zeros((len(preds or []), len(gts or [])))

    if etau.is_str(iscrowd):
        iscrowd = lambda l: bool(l.get_attribute_value(iscrowd, False))

    if isinstance(gts[0], fol.Polyline):
        if use_boxes:
            return _compute_bbox_ious(
                preds,
                gts,
                iscrowd=iscrowd,
                classwise=classwise,
                sparse=sparse,
            )

        if any(gt.filled for gt in gts):
            return _compute_polygon_ious(
                preds,
                gts,
                error_level,
                iscrowd=iscrowd,
                classwise=classwise,
                sparse=sparse,
            )

        return _compute_polyline_similarities(
            preds,
            gts,
            classwise=classwise,
            sparse=sparse,
        )

    if isinstance(gts[0], fol.Keypoint):
        return _compute_keypoint_similarities(
            preds,
            gts,
            classwise=classwise,
            sparse=sparse,
        )

    if use_masks:
        return _compute_mask_ious(
            preds,
            gts,
            tolerance,
            error_level,
            iscrowd=iscrowd,
            classwise=classwise,
            sparse=sparse,
        )

    return _compute_bbox_ious(
        preds,
        gts,
        iscrowd=iscrowd,
        classwise=classwise,
        sparse=sparse,
    )
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 <https://cocodataset.org/#keypoints-eval>`_.

    Args:
        preds: a list of predicted
            :class:`fiftyone.core.labels.Detection`,
            :class:`fiftyone.core.labels.Polyline`, or
            :class:`fiftyone.core.labels.Keypoints` instances
        gts: a list of ground truth
            :class:`fiftyone.core.labels.Detection`,
            :class:`fiftyone.core.labels.Polyline`, or
            :class:`fiftyone.core.labels.Keypoints` instances
        iscrowd (None): an 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 (False): whether 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 (False): whether to compute IoUs using the instances masks in
            the ``mask`` attribute of the provided objects, which must be
            :class:`fiftyone.core.labels.Detection` instances
        use_boxes (False): whether to compute IoUs using the bounding boxes
            of the provided :class:`fiftyone.core.labels.Polyline` instances
            rather than using their actual geometries
        tolerance (None): a tolerance, in pixels, when generating approximate
            polylines for instance masks. Typical values are 1-3 pixels. By
            default, IoUs are computed directly on the dense pixel masks
        sparse (False): whether 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``
    
fiftyone/utils/iou.py