diff --git a/supervision/__init__.py b/supervision/__init__.py index 62da6460..3e5c418c 100644 --- a/supervision/__init__.py +++ b/supervision/__init__.py @@ -46,35 +46,11 @@ from supervision.detection.line_zone import ( LineZoneAnnotator, LineZoneAnnotatorMulticlass, ) -from supervision.detection.utils.iou_and_nms import ( - box_iou, - box_iou_batch, - box_iou_batch_with_jaccard, - oriented_box_iou_batch, - mask_iou_batch, - OverlapFilter, - OverlapMetric, - box_non_max_merge, - box_non_max_suppression, - mask_non_max_suppression, -) -from supervision.detection.utils.masks import ( - move_masks, - calculate_masks_centroids, - contains_holes, - contains_multiple_segments -) -from supervision.detection.utils.converters import ( - xcycwh_to_xyxy, - xywh_to_xyxy, - xyxy_to_polygons, - xyxy_to_xcycarh, - xyxy_to_xywh, - mask_to_polygons, - mask_to_xyxy, - polygon_to_mask, - polygon_to_xyxy, -) +from supervision.detection.tools.csv_sink import CSVSink +from supervision.detection.tools.inference_slicer import InferenceSlicer +from supervision.detection.tools.json_sink import JSONSink +from supervision.detection.tools.polygon_zone import PolygonZone, PolygonZoneAnnotator +from supervision.detection.tools.smoother import DetectionsSmoother from supervision.detection.utils.boxes import ( clip_boxes, denormalize_boxes, @@ -82,15 +58,39 @@ from supervision.detection.utils.boxes import ( pad_boxes, scale_boxes, ) -from supervision.detection.utils.polygons import ( - filter_polygons_by_area, - approximate_polygon +from supervision.detection.utils.converters import ( + mask_to_polygons, + mask_to_xyxy, + polygon_to_mask, + polygon_to_xyxy, + xcycwh_to_xyxy, + xywh_to_xyxy, + xyxy_to_polygons, + xyxy_to_xcycarh, + xyxy_to_xywh, +) +from supervision.detection.utils.iou_and_nms import ( + OverlapFilter, + OverlapMetric, + box_iou, + box_iou_batch, + box_iou_batch_with_jaccard, + box_non_max_merge, + box_non_max_suppression, + mask_iou_batch, + mask_non_max_suppression, + oriented_box_iou_batch, +) +from supervision.detection.utils.masks import ( + calculate_masks_centroids, + contains_holes, + contains_multiple_segments, + move_masks, +) +from supervision.detection.utils.polygons import ( + approximate_polygon, + filter_polygons_by_area, ) -from supervision.detection.tools.csv_sink import CSVSink -from supervision.detection.tools.inference_slicer import InferenceSlicer -from supervision.detection.tools.json_sink import JSONSink -from supervision.detection.tools.polygon_zone import PolygonZone, PolygonZoneAnnotator -from supervision.detection.tools.smoother import DetectionsSmoother from supervision.detection.vlm import LMM, VLM from supervision.draw.color import Color, ColorPalette from supervision.draw.utils import ( @@ -192,6 +192,7 @@ __all__ = [ "VertexLabelAnnotator", "VideoInfo", "VideoSink", + "approximate_polygon", "box_iou", "box_iou_batch", "box_iou_batch_with_jaccard", @@ -244,5 +245,4 @@ __all__ = [ "xyxy_to_polygons", "xyxy_to_xcycarh", "xyxy_to_xywh", - "approximate_polygon" ] diff --git a/supervision/annotators/core.py b/supervision/annotators/core.py index 096198c5..6c142db1 100644 --- a/supervision/annotators/core.py +++ b/supervision/annotators/core.py @@ -22,10 +22,12 @@ from supervision.annotators.utils import ( ) from supervision.config import ORIENTED_BOX_COORDINATES from supervision.detection.core import Detections -from supervision.detection.utils.boxes import spread_out_boxes, clip_boxes -from supervision.detection.utils.converters import mask_to_polygons, xyxy_to_polygons, \ - polygon_to_mask - +from supervision.detection.utils.boxes import clip_boxes, spread_out_boxes +from supervision.detection.utils.converters import ( + mask_to_polygons, + polygon_to_mask, + xyxy_to_polygons, +) from supervision.draw.color import Color, ColorPalette from supervision.draw.utils import draw_polygon, draw_rounded_rectangle, draw_text from supervision.geometry.core import Point, Position, Rect diff --git a/supervision/dataset/formats/coco.py b/supervision/dataset/formats/coco.py index 34fb3fe1..b4827f29 100644 --- a/supervision/dataset/formats/coco.py +++ b/supervision/dataset/formats/coco.py @@ -15,7 +15,6 @@ from supervision.dataset.utils import ( from supervision.detection.core import Detections from supervision.detection.utils.converters import polygon_to_mask from supervision.detection.utils.masks import contains_holes, contains_multiple_segments - from supervision.utils.file import read_json_file, save_json_file if TYPE_CHECKING: diff --git a/supervision/dataset/utils.py b/supervision/dataset/utils.py index eb9af0b2..74050114 100644 --- a/supervision/dataset/utils.py +++ b/supervision/dataset/utils.py @@ -13,8 +13,10 @@ import numpy.typing as npt from supervision.detection.core import Detections from supervision.detection.utils.converters import mask_to_polygons -from supervision.detection.utils.polygons import filter_polygons_by_area, \ - approximate_polygon +from supervision.detection.utils.polygons import ( + approximate_polygon, + filter_polygons_by_area, +) if TYPE_CHECKING: from supervision.dataset.core import DetectionDataset diff --git a/supervision/detection/core.py b/supervision/detection/core.py index d492c52e..a616a821 100644 --- a/supervision/detection/core.py +++ b/supervision/detection/core.py @@ -18,15 +18,23 @@ from supervision.detection.tools.transformers import ( process_transformers_v5_segmentation_result, ) from supervision.detection.utils.converters import mask_to_xyxy, xywh_to_xyxy -from supervision.detection.utils.internal import get_data_item, is_data_equal, \ - is_metadata_equal, extract_ultralytics_masks, process_roboflow_result, merge_data, \ - merge_metadata +from supervision.detection.utils.internal import ( + extract_ultralytics_masks, + get_data_item, + is_data_equal, + is_metadata_equal, + merge_data, + merge_metadata, + process_roboflow_result, +) from supervision.detection.utils.iou_and_nms import ( OverlapMetric, + box_iou_batch, box_non_max_merge, box_non_max_suppression, + mask_iou_batch, mask_non_max_merge, - mask_non_max_suppression, mask_iou_batch, box_iou_batch, + mask_non_max_suppression, ) from supervision.detection.utils.masks import calculate_masks_centroids from supervision.detection.vlm import ( diff --git a/supervision/detection/utils/polygons.py b/supervision/detection/utils/polygons.py index 3998e700..c2773f2b 100644 --- a/supervision/detection/utils/polygons.py +++ b/supervision/detection/utils/polygons.py @@ -82,4 +82,4 @@ def approximate_polygon( else: break - return np.squeeze(approximated_points, axis=1) \ No newline at end of file + return np.squeeze(approximated_points, axis=1) diff --git a/supervision/metrics/f1_score.py b/supervision/metrics/f1_score.py index c68ebbad..a327eebe 100644 --- a/supervision/metrics/f1_score.py +++ b/supervision/metrics/f1_score.py @@ -9,9 +9,11 @@ from matplotlib import pyplot as plt from supervision.config import ORIENTED_BOX_COORDINATES from supervision.detection.core import Detections -from supervision.detection.utils.iou_and_nms import box_iou_batch, mask_iou_batch, \ - oriented_box_iou_batch - +from supervision.detection.utils.iou_and_nms import ( + box_iou_batch, + mask_iou_batch, + oriented_box_iou_batch, +) from supervision.draw.color import LEGACY_COLOR_PALETTE from supervision.metrics.core import AveragingMethod, Metric, MetricTarget from supervision.metrics.utils.object_size import ( diff --git a/supervision/metrics/mean_average_recall.py b/supervision/metrics/mean_average_recall.py index b96582d9..07933cf0 100644 --- a/supervision/metrics/mean_average_recall.py +++ b/supervision/metrics/mean_average_recall.py @@ -9,9 +9,11 @@ from matplotlib import pyplot as plt from supervision.config import ORIENTED_BOX_COORDINATES from supervision.detection.core import Detections -from supervision.detection.utils.iou_and_nms import box_iou_batch, mask_iou_batch, \ - oriented_box_iou_batch - +from supervision.detection.utils.iou_and_nms import ( + box_iou_batch, + mask_iou_batch, + oriented_box_iou_batch, +) from supervision.draw.color import LEGACY_COLOR_PALETTE from supervision.metrics.core import Metric, MetricTarget from supervision.metrics.utils.object_size import ( diff --git a/supervision/metrics/precision.py b/supervision/metrics/precision.py index 4916094a..04b4e256 100644 --- a/supervision/metrics/precision.py +++ b/supervision/metrics/precision.py @@ -9,8 +9,11 @@ from matplotlib import pyplot as plt from supervision.config import ORIENTED_BOX_COORDINATES from supervision.detection.core import Detections -from supervision.detection.utils.iou_and_nms import box_iou_batch, mask_iou_batch, \ - oriented_box_iou_batch +from supervision.detection.utils.iou_and_nms import ( + box_iou_batch, + mask_iou_batch, + oriented_box_iou_batch, +) from supervision.draw.color import LEGACY_COLOR_PALETTE from supervision.metrics.core import AveragingMethod, Metric, MetricTarget from supervision.metrics.utils.object_size import ( diff --git a/supervision/metrics/recall.py b/supervision/metrics/recall.py index 582eb8ba..4a555072 100644 --- a/supervision/metrics/recall.py +++ b/supervision/metrics/recall.py @@ -9,9 +9,11 @@ from matplotlib import pyplot as plt from supervision.config import ORIENTED_BOX_COORDINATES from supervision.detection.core import Detections -from supervision.detection.utils.iou_and_nms import box_iou_batch, mask_iou_batch, \ - oriented_box_iou_batch - +from supervision.detection.utils.iou_and_nms import ( + box_iou_batch, + mask_iou_batch, + oriented_box_iou_batch, +) from supervision.draw.color import LEGACY_COLOR_PALETTE from supervision.metrics.core import AveragingMethod, Metric, MetricTarget from supervision.metrics.utils.object_size import ( diff --git a/test/detection/tools/test_inference_slicer.py b/test/detection/tools/test_inference_slicer.py index ba66cbe1..2185b77f 100644 --- a/test/detection/tools/test_inference_slicer.py +++ b/test/detection/tools/test_inference_slicer.py @@ -6,8 +6,8 @@ import numpy as np import pytest from supervision.detection.core import Detections -from supervision.detection.utils.iou_and_nms import OverlapFilter from supervision.detection.tools.inference_slicer import InferenceSlicer +from supervision.detection.utils.iou_and_nms import OverlapFilter @pytest.fixture diff --git a/test/detection/utils/test_boxes.py b/test/detection/utils/test_boxes.py index d6bf1acc..91998928 100644 --- a/test/detection/utils/test_boxes.py +++ b/test/detection/utils/test_boxes.py @@ -141,4 +141,4 @@ def test_scale_boxes( ) -> None: with exception: result = scale_boxes(xyxy=xyxy, factor=factor) - assert np.array_equal(result, expected_result) \ No newline at end of file + assert np.array_equal(result, expected_result) diff --git a/test/detection/utils/test_converters.py b/test/detection/utils/test_converters.py index 55146a99..e13b1500 100644 --- a/test/detection/utils/test_converters.py +++ b/test/detection/utils/test_converters.py @@ -3,8 +3,12 @@ from __future__ import annotations import numpy as np import pytest -from supervision.detection.utils.converters import xywh_to_xyxy, xyxy_to_xywh, \ - xyxy_to_xcycarh, xcycwh_to_xyxy +from supervision.detection.utils.converters import ( + xcycwh_to_xyxy, + xywh_to_xyxy, + xyxy_to_xcycarh, + xyxy_to_xywh, +) @pytest.mark.parametrize( @@ -124,4 +128,4 @@ def test_xyxy_to_xcycarh(xyxy: np.ndarray, expected_result: np.ndarray) -> None: ) def test_xcycwh_to_xyxy(xcycwh: np.ndarray, expected_result: np.ndarray) -> None: result = xcycwh_to_xyxy(xcycwh) - np.testing.assert_array_equal(result, expected_result) \ No newline at end of file + np.testing.assert_array_equal(result, expected_result) diff --git a/test/detection/utils/test_internal.py b/test/detection/utils/test_internal.py index 525cf3b3..0164d323 100644 --- a/test/detection/utils/test_internal.py +++ b/test/detection/utils/test_internal.py @@ -7,8 +7,12 @@ import numpy as np import pytest from supervision.config import CLASS_NAME_DATA_FIELD -from supervision.detection.utils.internal import process_roboflow_result, merge_data, \ - get_data_item, merge_metadata +from supervision.detection.utils.internal import ( + get_data_item, + merge_data, + merge_metadata, + process_roboflow_result, +) TEST_MASK = np.zeros((1, 1000, 1000), dtype=bool) TEST_MASK[:, 300:351, 200:251] = True @@ -245,6 +249,7 @@ def test_process_roboflow_result( f"Mismatch in non-array data for key {key}" ) + @pytest.mark.parametrize( "data_list, expected_result, exception", [ diff --git a/test/detection/utils/test_iou_and_nms.py b/test/detection/utils/test_iou_and_nms.py index abd19b88..8039bf24 100644 --- a/test/detection/utils/test_iou_and_nms.py +++ b/test/detection/utils/test_iou_and_nms.py @@ -5,8 +5,12 @@ from contextlib import ExitStack as DoesNotRaise import numpy as np import pytest -from supervision.detection.utils.iou_and_nms import box_non_max_suppression, \ - mask_non_max_suppression, mask_non_max_merge, _group_overlapping_boxes +from supervision.detection.utils.iou_and_nms import ( + _group_overlapping_boxes, + box_non_max_suppression, + mask_non_max_merge, + mask_non_max_suppression, +) @pytest.mark.parametrize( diff --git a/test/detection/utils/test_masks.py b/test/detection/utils/test_masks.py index 15fb4945..2097f608 100644 --- a/test/detection/utils/test_masks.py +++ b/test/detection/utils/test_masks.py @@ -6,8 +6,12 @@ import numpy as np import numpy.typing as npt import pytest -from supervision.detection.utils.masks import move_masks, calculate_masks_centroids, \ - contains_holes, contains_multiple_segments +from supervision.detection.utils.masks import ( + calculate_masks_centroids, + contains_holes, + contains_multiple_segments, + move_masks, +) @pytest.mark.parametrize( diff --git a/test/detection/utils/test_polygons.py b/test/detection/utils/test_polygons.py index a3c02342..c1ac0f3a 100644 --- a/test/detection/utils/test_polygons.py +++ b/test/detection/utils/test_polygons.py @@ -99,4 +99,4 @@ def test_filter_polygons_by_area( ) assert len(result) == len(expected_result) for result_polygon, expected_result_polygon in zip(result, expected_result): - assert np.array_equal(result_polygon, expected_result_polygon) \ No newline at end of file + assert np.array_equal(result_polygon, expected_result_polygon)