From 5bf78e55053c080e454c3923ab2d23dfcc6a8024 Mon Sep 17 00:00:00 2001 From: SkalskiP Date: Tue, 27 Jun 2023 02:52:20 +0200 Subject: [PATCH] naming refactor --- supervision/dataset/formats/coco.py | 28 ++++++++++++++-------------- supervision/detection/core.py | 14 -------------- 2 files changed, 14 insertions(+), 28 deletions(-) diff --git a/supervision/dataset/formats/coco.py b/supervision/dataset/formats/coco.py index b9ea4fdb..fac0b1af 100644 --- a/supervision/dataset/formats/coco.py +++ b/supervision/dataset/formats/coco.py @@ -91,12 +91,12 @@ def coco_annotations_to_detections( def detections_to_coco_annotations( detections: Detections, image_id: int, - label_id: int, + annotation_id: int, min_image_area_percentage: float = 0.0, max_image_area_percentage: float = 1.0, approximation_percentage: float = 0.75, ) -> Tuple[List[Dict], int]: - annotations_data = [] + coco_annotations = [] for xyxy, mask, confidence, class_id, tracker_id in detections: polygon = [] if mask is not None: @@ -109,18 +109,18 @@ def detections_to_coco_annotations( )[0].flatten() ) - per_label_dict = {} - per_label_dict["id"] = label_id - per_label_dict["image_id"] = image_id - per_label_dict["category_id"] = int(class_id) + coco_annotation = {} + coco_annotation["id"] = annotation_id + coco_annotation["image_id"] = image_id + coco_annotation["category_id"] = int(class_id) box_width, box_height = xyxy[2] - xyxy[0], xyxy[3] - xyxy[1] - per_label_dict["bbox"] = [xyxy[0], xyxy[1], box_width, box_height] - per_label_dict["area"] = box_width * box_height - per_label_dict["segmentation"] = polygon - per_label_dict["iscrowd"] = 0 - annotations_data.append(per_label_dict) - label_id += 1 - return annotations_data, label_id + coco_annotation["bbox"] = [xyxy[0], xyxy[1], box_width, box_height] + coco_annotation["area"] = box_width * box_height + coco_annotation["segmentation"] = polygon + coco_annotation["iscrowd"] = 0 + coco_annotations.append(coco_annotation) + annotation_id += 1 + return coco_annotations, annotation_id def load_coco_annotations( @@ -218,7 +218,7 @@ def save_coco_annotations( coco_annotation, label_id = detections_to_coco_annotations( detections=detections, image_id=image_id, - label_id=annotation_id, + annotation_id=annotation_id, min_image_area_percentage=min_image_area_percentage, max_image_area_percentage=max_image_area_percentage, approximation_percentage=approximation_percentage, diff --git a/supervision/detection/core.py b/supervision/detection/core.py index 97150e45..93c8e1fb 100644 --- a/supervision/detection/core.py +++ b/supervision/detection/core.py @@ -355,20 +355,6 @@ class Detections: return Detections(xyxy=xywh_to_xyxy(boxes_xywh=xywh), mask=mask) - @classmethod - @deprecated( - "Dataset loading and saving is going to be executed by supervision.dataset.core.Dataset" - ) - def from_coco_annotations(cls, coco_annotation: dict) -> Detections: - xyxy, class_id = [], [] - - for annotation in coco_annotation: - x_min, y_min, width, height = annotation["bbox"] - xyxy.append([x_min, y_min, x_min + width, y_min + height]) - class_id.append(annotation["category_id"]) - - return cls(xyxy=np.array(xyxy), class_id=np.array(class_id)) - @classmethod def empty(cls) -> Detections: """