From 59b273ba87e30e406e8036560bd0c3348a86287c Mon Sep 17 00:00:00 2001 From: SkalskiP Date: Mon, 13 May 2024 12:25:25 +0200 Subject: [PATCH] small refactor --- supervision/dataset/formats/coco.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/supervision/dataset/formats/coco.py b/supervision/dataset/formats/coco.py index 4beb1dcd..fc62ac66 100644 --- a/supervision/dataset/formats/coco.py +++ b/supervision/dataset/formats/coco.py @@ -5,6 +5,7 @@ from typing import Dict, List, Tuple import cv2 import numpy as np +import numpy.typing as npt from supervision.dataset.utils import ( approximate_mask_with_polygons, @@ -58,7 +59,10 @@ def group_coco_annotations_by_image_id( return annotations -def _annotations_to_mask(image_annotations: List[dict], resolution_wh: Tuple[int, int]): +def coco_annotations_to_masks( + image_annotations: List[dict], + resolution_wh: Tuple[int, int] +) -> npt.NDArray[np.bool_]: return np.array( [ rle_to_mask( @@ -93,7 +97,10 @@ def coco_annotations_to_detections( xyxy[:, 2:4] += xyxy[:, 0:2] if with_masks: - mask = _annotations_to_mask(image_annotations, resolution_wh) + mask = coco_annotations_to_masks( + image_annotations=image_annotations, + resolution_wh=resolution_wh + ) return Detections( class_id=np.asarray(class_ids, dtype=int), xyxy=xyxy, mask=mask )