Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/datumaro/plugins/data_formats/coco/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,8 @@ def _load_panoptic_ann(self, ann, parsed_annotations=None):
for segm_info in self._parse_field(ann, "segments_info", list):
cat_id = self._get_label_id(segm_info)
segm_id = self._parse_field(segm_info, "id", int)
attributes = {"is_crowd": bool(self._parse_field(segm_info, "iscrowd", int))}
attributes = segm_info.get("attributes", {})
attributes["is_crowd"] = bool(self._parse_field(segm_info, "iscrowd", int))
parsed_annotations.append(
Mask(
image=mask.lazy_extract(segm_id),
Expand Down
4 changes: 4 additions & 0 deletions src/datumaro/plugins/data_formats/coco/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,10 @@ def save_annotations(self, item):
segment_info["area"] = float(ann.get_area())
segment_info["bbox"] = [float(p) for p in ann.get_bbox()]
segment_info["iscrowd"] = cast(ann.attributes.get("is_crowd"), int, 0)
if self._context._allow_attributes:
attrs = self._convert_attributes(ann)
if attrs:
segment_info["attributes"] = attrs
segments_info.append(segment_info)
masks.append(ann)

Expand Down
30 changes: 30 additions & 0 deletions tests/unit/test_coco_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -1639,6 +1639,36 @@ def test_can_save_and_load_panoptic(self, test_dir, stream: bool):
stream=stream,
)

def test_can_save_and_load_panoptic_with_attributes(self, test_dir, stream: bool):
dataset = Dataset.from_iterable(
[
DatasetItem(
id=1,
subset="train",
media=Image.from_numpy(data=np.ones((4, 4, 3))),
annotations=[
Mask(
image=np.array([[0, 1, 0, 0], [0, 1, 0, 0], [0, 1, 1, 1], [0, 0, 0, 0]]),
attributes={"is_crowd": False, "x": 5, "y": "abc"},
label=4,
group=3,
id=3,
),
],
attributes={"id": 1},
),
],
categories=[str(i) for i in range(10)],
)

self._test_save_and_load(
dataset,
partial(CocoPanopticExporter.convert, save_media=True),
test_dir,
require_media=True,
stream=stream,
)

def test_can_save_and_load_stuff(self, test_dir, stream: bool):
source_dataset = Dataset.from_iterable(
[
Expand Down