Skip to content

Commit 0ba99e1

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

File tree

4 files changed

+385
-12
lines changed

4 files changed

+385
-12
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: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -412,17 +412,28 @@ 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
)
422+
else:
423+
x, y, w, h = bbox
424+
parsed_annotations.append(
425+
Bbox(
426+
x,
427+
y,
428+
w,
429+
h,
430+
label=label_id,
431+
id=ann_id,
432+
attributes=attributes,
433+
group=group,
434+
)
435+
)
421436

422-
x, y, w, h = bbox
423-
parsed_annotations.append(
424-
Bbox(x, y, w, h, label=label_id, id=ann_id, attributes=attributes, group=group)
425-
)
426437
elif self._task is CocoTask.labels:
427438
label_id = self._get_label_id(ann)
428439
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)