Skip to content

Commit 6e88f45

Browse files
Fix COCO import when the segmentation element is empty.
1 parent c35dba2 commit 6e88f45

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

backend/webserver/util/coco_util.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,9 @@ def get_image_coco(image_id):
248248

249249
has_segmentation = len(annotation.get('segmentation', [])) > 0
250250
has_keypoints = len(annotation.get('keypoints', [])) > 0
251+
has_bbox = len(annotation.get('bbox', [])) > 0
251252

252-
if has_segmentation or has_keypoints:
253+
if has_segmentation or has_keypoints or has_bbox:
253254

254255
if has_keypoints:
255256
arr = np.array(annotation.get('keypoints', []))

backend/workers/tasks/data.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,19 +231,21 @@ def import_annotations(task_id, dataset_id, coco_json):
231231
category_id = annotation.get('category_id')
232232
segmentation = annotation.get('segmentation', [])
233233
keypoints = annotation.get('keypoints', [])
234+
bboxes = annotation.get('bbox', [])
234235
# is_crowd = annotation.get('iscrowed', False)
235236
area = annotation.get('area', 0)
236237
bbox = annotation.get('bbox', [0, 0, 0, 0])
237-
isbbox = annotation.get('isbbox', False)
238+
isbbox = annotation.get('isbbox', False) if len(bboxes) == 0 else len(bboxes) > 0
238239

239240
progress += 1
240241
task.set_progress((progress / total_items) * 100, socket=socket)
241242

242243
has_segmentation = len(segmentation) > 0
243244
has_keypoints = len(keypoints) > 0
244-
if not has_segmentation and not has_keypoints:
245+
has_bbox = len(bboxes) > 0
246+
if not has_segmentation and not has_keypoints and not has_bbox:
245247
task.warning(
246-
f"Annotation {annotation.get('id')} has no segmentation or keypoints")
248+
f"Annotation {annotation.get('id')} has none of segmentation, keypoints and bounding boxes")
247249
continue
248250

249251
try:

0 commit comments

Comments
 (0)