diff --git a/supervision/detection/core.py b/supervision/detection/core.py index 7b06f087..db6297c2 100644 --- a/supervision/detection/core.py +++ b/supervision/detection/core.py @@ -249,6 +249,9 @@ class Detections: Raises: AssertionError: If `confidence` is None and class_agnostic is False. If `class_id` is None and class_agnostic is False. """ + if len(self) == 0: + return self + assert ( self.confidence is not None ), f"Detections confidence must be given for NMS to be executed." diff --git a/test/detection/test_utils.py b/test/detection/test_utils.py index 9ddf3cc5..110b682e 100644 --- a/test/detection/test_utils.py +++ b/test/detection/test_utils.py @@ -11,6 +11,12 @@ from supervision.detection.utils import non_max_suppression @pytest.mark.parametrize( "predictions, iou_threshold, expected_result, exception", [ + ( + np.empty(shape=(0, 5)), + 0.5, + np.array([]), + DoesNotRaise() + ), # single box with no category ( np.array([ [10.0, 10.0, 40.0, 40.0, 0.8]