From 879cf6d9dcc42fcdbd1cf744c8340c0050b9bf87 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 7 Feb 2024 05:15:09 +0000 Subject: [PATCH] =?UTF-8?q?fix(pre=5Fcommit):=20=F0=9F=8E=A8=20auto=20form?= =?UTF-8?q?at=20pre-commit=20hooks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- supervision/detection/core.py | 2 +- supervision/detection/utils.py | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/supervision/detection/core.py b/supervision/detection/core.py index cef7fef1..e727426b 100644 --- a/supervision/detection/core.py +++ b/supervision/detection/core.py @@ -1002,7 +1002,7 @@ class Detections: self, threshold: float = 0.5, class_agnostic: bool = False ) -> Detections: """ - Performs non-max suppression on detection set. If the detections result + Performs non-max suppression on detection set. If the detections result from a segmentation model, the IoU mask is applied. Otherwise, box IoU is used. Args: diff --git a/supervision/detection/utils.py b/supervision/detection/utils.py index 4e3a6bb0..ac41299a 100644 --- a/supervision/detection/utils.py +++ b/supervision/detection/utils.py @@ -72,13 +72,21 @@ def mask_iou_batch(masks_true: np.ndarray, masks_detection: np.ndarray) -> np.nd Returns: np.ndarray: Pairwise IoU of masks from `masks_true` and `masks_detection`. """ - intersection_area = np.logical_and(masks_true[:, None], masks_detection).sum(axis=(2, 3)) - masks_true_area = masks_true.sum(axis=(1, 2)) + intersection_area = np.logical_and(masks_true[:, None], masks_detection).sum( + axis=(2, 3) + ) + masks_true_area = masks_true.sum(axis=(1, 2)) masks_detection_area = masks_detection.sum(axis=(1, 2)) union_area = masks_true_area[:, None] + masks_detection_area - intersection_area - return np.divide(intersection_area, union_area, out=np.zeros_like(intersection_area, dtype=float), where=union_area != 0) + return np.divide( + intersection_area, + union_area, + out=np.zeros_like(intersection_area, dtype=float), + where=union_area != 0, + ) + def resize_masks(masks: np.ndarray, max_dimension: int = 640) -> np.ndarray: """ @@ -108,6 +116,7 @@ def resize_masks(masks: np.ndarray, max_dimension: int = 640) -> np.ndarray: resized_masks = resized_masks.reshape(masks.shape[0], new_height, new_width) return resized_masks + def mask_non_max_suppression( predictions: np.ndarray, masks: np.ndarray, iou_threshold: float = 0.5 ) -> np.ndarray: