From 4e2f9e0f7df9cb4021938835815b21b173c503ac Mon Sep 17 00:00:00 2001 From: Laurent Date: Mon, 2 Sep 2024 11:35:13 +0000 Subject: [PATCH] apply suggestions --- fiftyone/core/labels.py | 43 ----------------------------------------- fiftyone/utils/coco.py | 4 ++-- fiftyone/utils/cvat.py | 2 +- 3 files changed, 3 insertions(+), 46 deletions(-) diff --git a/fiftyone/core/labels.py b/fiftyone/core/labels.py index 64a58d4eef..139896533a 100644 --- a/fiftyone/core/labels.py +++ b/fiftyone/core/labels.py @@ -470,49 +470,6 @@ def export_mask(self, outpath, update=False): self.mask = None self.mask_path = outpath - def transform_mask(self, targets_map, outpath=None, update=False): - """Transforms this instance's mask according to the provided targets - map. - - This method can be used to transform between grayscale and RGB masks, - or it can be used to edit the pixel values or colors of a mask without - changing the number of channels. - - Note that any pixel values not in ``targets_map`` will be zero in the - transformed mask. - - Args: - targets_map: a dict mapping existing pixel values (2D masks) or RGB - hex strings (3D masks) to new pixel values or RGB hex strings. - You may convert between grayscale and RGB using this argument - outpath (None): an optional path to write the transformed mask on - disk - update (False): whether to save the transformed mask on this - instance - - Returns: - the transformed mask - """ - mask = self.get_mask() - if mask is None: - return - - mask = _transform_mask(mask, targets_map) - - if outpath is not None: - _write_mask(mask, outpath) - - if update: - self.mask = None - self.mask_path = outpath - elif update: - if self.mask_path is not None: - _write_mask(mask, self.mask_path) - else: - self.mask = mask - - return mask - def to_polyline(self, tolerance=2, filled=True): """Returns a :class:`Polyline` representation of this instance. diff --git a/fiftyone/utils/coco.py b/fiftyone/utils/coco.py index 2bfcc42506..44a2e69426 100644 --- a/fiftyone/utils/coco.py +++ b/fiftyone/utils/coco.py @@ -1304,7 +1304,7 @@ def from_label( x, y, w, h = label.bounding_box bbox = [x * width, y * height, w * width, h * height] - if label.get_mask() is not None: + if label.has_mask() is not None: segmentation = _instance_to_coco_segmentation( label, frame_size, iscrowd=iscrowd, tolerance=tolerance ) @@ -2116,7 +2116,7 @@ def _coco_objects_to_detections( ) if detection is not None and ( - not load_segmentations or detection.get_mask() is not None + not load_segmentations or detection.has_mask() is not None ): detections.append(detection) diff --git a/fiftyone/utils/cvat.py b/fiftyone/utils/cvat.py index 9df03932d0..f546909543 100644 --- a/fiftyone/utils/cvat.py +++ b/fiftyone/utils/cvat.py @@ -6400,7 +6400,7 @@ def _create_detection_shapes( } ) elif label_type in ("instance", "instances"): - if det.get_mask() is None: + if det.has_mask() is None: continue polygon = det.to_polyline()