Skip to content

Commit

Permalink
apply suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Laurent2916 authored and sashankaryal committed Nov 14, 2024
1 parent 936241e commit 4e2f9e0
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 46 deletions.
43 changes: 0 additions & 43 deletions fiftyone/core/labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions fiftyone/utils/coco.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion fiftyone/utils/cvat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 4e2f9e0

Please sign in to comment.