From 9462a3058d3bf57cc428afc28f454ce645cf0d9e Mon Sep 17 00:00:00 2001 From: kirilllzaitsev Date: Mon, 31 Jul 2023 13:15:40 +0200 Subject: [PATCH] cast masks to bool only when creating a Detection obj --- supervision/dataset/formats/pascal_voc.py | 3 +-- supervision/detection/utils.py | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/supervision/dataset/formats/pascal_voc.py b/supervision/dataset/formats/pascal_voc.py index 93e90927..18f130c7 100644 --- a/supervision/dataset/formats/pascal_voc.py +++ b/supervision/dataset/formats/pascal_voc.py @@ -242,14 +242,13 @@ def detections_from_xml_obj( ) if with_masks: - annotation = Detections(xyxy=xyxy, mask=np.array(masks), class_id=class_id) + annotation = Detections(xyxy=xyxy, mask=np.array(masks).astype(bool), class_id=class_id) else: annotation = Detections(xyxy=xyxy, class_id=class_id) return annotation, extended_classes def parse_polygon_points(polygon: Element) -> List[List[int]]: - # Parses polygon points in format: ............... polygon_points = [] coords = polygon.findall(".//*") for i in range(0, len(coords), 2): diff --git a/supervision/detection/utils.py b/supervision/detection/utils.py index cdca3ff7..e30e6a05 100644 --- a/supervision/detection/utils.py +++ b/supervision/detection/utils.py @@ -19,7 +19,6 @@ def polygon_to_mask(polygon: np.ndarray, resolution_wh: Tuple[int, int]) -> np.n width, height = resolution_wh mask = np.zeros((height, width)) cv2.fillPoly(mask, [polygon], color=1) - mask = mask.astype(bool) return mask