diff --git a/supervision/detection/core.py b/supervision/detection/core.py index ae6205df..bda2e7de 100644 --- a/supervision/detection/core.py +++ b/supervision/detection/core.py @@ -296,7 +296,10 @@ class Detections: class_id=np.arange(len(ultralytics_results)), ) - if hasattr(ultralytics_results, "boxes") and ultralytics_results.boxes is not None: + if ( + hasattr(ultralytics_results, "boxes") + and ultralytics_results.boxes is not None + ): class_id = ultralytics_results.boxes.cls.cpu().numpy().astype(int) class_names = np.array([ultralytics_results.names[i] for i in class_id]) return cls( diff --git a/test/detection/test_core.py b/test/detection/test_core.py index 1542f0a3..bf27f209 100644 --- a/test/detection/test_core.py +++ b/test/detection/test_core.py @@ -816,6 +816,7 @@ def test_merge_inner_detection_object_pair( result = merge_inner_detection_object_pair(detection_1, detection_2) assert result == expected_result + class TestFromUltralytics: """Test suite for Detections.from_ultralytics method.""" @@ -824,6 +825,7 @@ class TestFromUltralytics: Regression test for issue #2000. """ + # Create a mock ultralytics result without boxes attribute class MockUltralyticsResult: def __init__(self): @@ -839,6 +841,7 @@ class TestFromUltralytics: def test_from_ultralytics_with_boxes_none(self): """Test that from_ultralytics handles boxes=None (segmentation-only models).""" + # Create a mock ultralytics result with boxes=None class MockUltralyticsResult: def __init__(self): @@ -859,6 +862,7 @@ class TestFromUltralytics: def test_from_ultralytics_with_valid_boxes(self): """Test that from_ultralytics works correctly with valid boxes.""" + # Create a mock ultralytics result with valid boxes class MockBoxes: def __init__(self):