Skip to content

Commit cf7fa13

Browse files
author
Matt Sokoloff
committed
update class logic for seg masks
1 parent 06c0a32 commit cf7fa13

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

labelbox/data/serialization/coco/panoptic_dataset.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,13 @@ def vector_to_coco_segment_info(canvas: np.ndarray,
3333
bbox=[xmin, ymin, xmax - xmin, ymax - ymin])
3434

3535

36-
def mask_to_coco_segment_info(canvas: np.ndarray, annotation, category_id):
37-
# Expects a unique color for each class....
38-
# Also there is a possible conflict with vector classes being draw. TODO: Use ID instead
39-
mask = annotation.value.draw()
36+
def mask_to_coco_segment_info(canvas: np.ndarray, annotation, annotation_idx: int, category_id):
37+
color = id_to_rgb(annotation_idx)
38+
mask = annotation.value.draw(color = color)
4039
shapely = annotation.value.shapely
4140
xmin, ymin, xmax, ymax = shapely.bounds
4241
canvas = np.where(canvas == (0, 0, 0), mask, canvas)
43-
id = rgb_to_id(*annotation.value.color)
44-
return SegmentInfo(id=id,
42+
return SegmentInfo(id=annotation_idx,
4543
category_id=category_id,
4644
area=shapely.area,
4745
bbox=[xmin, ymin, xmax - xmin, ymax - ymin]), canvas
@@ -66,7 +64,7 @@ def process_label(label: Label, idx: Union[int, str], image_root, mask_root, all
6664
categories[annotation.name] = hash_category_name(annotation.name)
6765
if isinstance(annotation.value, Mask):
6866
segment, canvas = (mask_to_coco_segment_info(
69-
canvas, annotation, categories[annotation.name]))
67+
canvas, annotation, class_idx ,categories[annotation.name]))
7068
segments.append(segment)
7169
is_thing[annotation.name] = 0
7270

@@ -79,7 +77,6 @@ def process_label(label: Label, idx: Union[int, str], image_root, mask_root, all
7977
image=image,
8078
category_id=categories[annotation.name]))
8179
is_thing[annotation.name] = 1 - int(all_stuff)
82-
# TODO: Report on unconverted annotations.
8380

8481
mask_file = image.file_name.replace('.jpg', '.png')
8582
mask_file = os.path.join(mask_root, mask_file)

0 commit comments

Comments
 (0)