Skip to content

Commit cbf591e

Browse files
committed
COCO enable bbox with segement annotation
1 parent d84c42d commit cbf591e

File tree

4 files changed

+382
-10
lines changed

4 files changed

+382
-10
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4141
(<https://github.com/openvinotoolkit/datumaro/pull/767>)
4242
- Fix a VOC dataset export when a label contains 'space'
4343
(<https://github.com/openvinotoolkit/datumaro/pull/771>)
44+
- Keep 'bbox' annotation when importing a COCO dataset
45+
(<https://github.com/openvinotoolkit/datumaro/pull/772>)
4446

4547
### Changed
4648
- Wrap title text according to its plot width

datumaro/plugins/data_formats/coco/base.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -412,17 +412,27 @@ def _load_annotations(self, ann, image_info=None, parsed_annotations=None):
412412
rle=rle, label=label_id, id=ann_id, attributes=attributes, group=group
413413
)
414414
)
415-
else:
416-
bbox = self._parse_field(ann, "bbox", list)
415+
416+
bbox = self._parse_field(ann, "bbox", list)
417+
if bbox and len(bbox) > 0:
417418
if len(bbox) != 4:
418419
raise InvalidAnnotationError(
419420
f"Bbox has wrong value count {len(bbox)}. Expected 4 values."
420421
)
421-
422422
x, y, w, h = bbox
423423
parsed_annotations.append(
424-
Bbox(x, y, w, h, label=label_id, id=ann_id, attributes=attributes, group=group)
424+
Bbox(
425+
x,
426+
y,
427+
w,
428+
h,
429+
label=label_id,
430+
id=ann_id,
431+
attributes=attributes,
432+
group=group,
433+
)
425434
)
435+
426436
elif self._task is CocoTask.labels:
427437
label_id = self._get_label_id(ann)
428438
parsed_annotations.append(

datumaro/plugins/data_formats/coco/exporter.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,10 @@ def find_instance_parts(self, group, img_width, img_height):
208208

209209
anns = boxes + polygons + masks
210210
leader = anno_tools.find_group_leader(anns)
211-
bbox = anno_tools.max_bbox(anns)
211+
if len(boxes) > 0:
212+
bbox = anno_tools.max_bbox(boxes)
213+
else:
214+
bbox = anno_tools.max_bbox(anns)
212215
mask = None
213216
polygons = [p.points for p in polygons]
214217

0 commit comments

Comments
 (0)