From 534df93a52c7b29dc82e3d4d8e2c44217cda9e8f Mon Sep 17 00:00:00 2001 From: Wonju Lee Date: Wed, 20 Mar 2024 17:52:27 +0900 Subject: [PATCH 1/4] enable to import coco detection --- src/datumaro/plugins/data_formats/coco/base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/datumaro/plugins/data_formats/coco/base.py b/src/datumaro/plugins/data_formats/coco/base.py index a05d128421..f00a6bff86 100644 --- a/src/datumaro/plugins/data_formats/coco/base.py +++ b/src/datumaro/plugins/data_formats/coco/base.py @@ -29,7 +29,6 @@ DatasetImportError, InvalidAnnotationError, InvalidFieldTypeError, - MissingFieldError, UndeclaredLabelError, ) from datumaro.components.importer import ImportContext @@ -450,7 +449,8 @@ def _parse_field( ) -> Any: value = ann.get(key, NOTSET) if value is NOTSET: - raise MissingFieldError(key) + log.warning(f"field '{key}' is no existed in the annotation file") + return None elif not isinstance(value, cls): cls = (cls,) if isclass(cls) else cls raise InvalidFieldTypeError( From d9e4ca8ea7ff95ff263be22f716466dfce94af70 Mon Sep 17 00:00:00 2001 From: Wonju Lee Date: Wed, 20 Mar 2024 17:54:32 +0900 Subject: [PATCH 2/4] update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f6229f7f73..8a16f9d746 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -81,6 +81,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 () - Fix explore command without project () +- Fix enable COCO to import only bboxes + () ## Jan. 2024 Release 1.5.2 ### Enhancements From 183a69e1ac8310ba9d8c4fec5f22067328fa1fa6 Mon Sep 17 00:00:00 2001 From: Wonju Lee Date: Wed, 20 Mar 2024 17:55:56 +0900 Subject: [PATCH 3/4] fix type --- src/datumaro/plugins/data_formats/coco/base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/datumaro/plugins/data_formats/coco/base.py b/src/datumaro/plugins/data_formats/coco/base.py index f00a6bff86..1eccfe7b37 100644 --- a/src/datumaro/plugins/data_formats/coco/base.py +++ b/src/datumaro/plugins/data_formats/coco/base.py @@ -1,4 +1,4 @@ -# Copyright (C) 2019-2022 Intel Corporation +# Copyright (C) 2019-2024 Intel Corporation # # SPDX-License-Identifier: MIT @@ -449,7 +449,7 @@ def _parse_field( ) -> Any: value = ann.get(key, NOTSET) if value is NOTSET: - log.warning(f"field '{key}' is no existed in the annotation file") + log.warning(f"field '{key}' is not existed in the annotation file.") return None elif not isinstance(value, cls): cls = (cls,) if isclass(cls) else cls From dc703b6ae98202e41144601349e56c741c890e19 Mon Sep 17 00:00:00 2001 From: Wonju Lee Date: Wed, 20 Mar 2024 19:34:29 +0900 Subject: [PATCH 4/4] fix missing field error for segmentation --- src/datumaro/plugins/data_formats/coco/base.py | 11 ++++++++--- tests/unit/test_coco_format.py | 3 ++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/datumaro/plugins/data_formats/coco/base.py b/src/datumaro/plugins/data_formats/coco/base.py index 1eccfe7b37..0297c1f5d4 100644 --- a/src/datumaro/plugins/data_formats/coco/base.py +++ b/src/datumaro/plugins/data_formats/coco/base.py @@ -29,6 +29,7 @@ DatasetImportError, InvalidAnnotationError, InvalidFieldTypeError, + MissingFieldError, UndeclaredLabelError, ) from datumaro.components.importer import ImportContext @@ -449,8 +450,7 @@ def _parse_field( ) -> Any: value = ann.get(key, NOTSET) if value is NOTSET: - log.warning(f"field '{key}' is not existed in the annotation file.") - return None + raise MissingFieldError(key) elif not isinstance(value, cls): cls = (cls,) if isclass(cls) else cls raise InvalidFieldTypeError( @@ -505,7 +505,12 @@ def _load_annotations(self, ann, image_info=None, parsed_annotations=None): ) ) - segmentation = self._parse_field(ann, "segmentation", (list, dict)) + try: + segmentation = self._parse_field(ann, "segmentation", (list, dict)) + except MissingFieldError as e: + log.warn(str(e)) + segmentation = None + if segmentation and segmentation != [[]]: rle = None diff --git a/tests/unit/test_coco_format.py b/tests/unit/test_coco_format.py index 0dd2bc2bab..0ec8420b6a 100644 --- a/tests/unit/test_coco_format.py +++ b/tests/unit/test_coco_format.py @@ -1255,7 +1255,8 @@ def test_can_report_missing_item_field(self): @mark_requirement(Requirements.DATUM_ERROR_REPORTING) def test_can_report_missing_ann_field(self): - for field in ["id", "image_id", "segmentation", "iscrowd", "category_id", "bbox"]: + # https://github.com/openvinotoolkit/datumaro/issues/1344 requires to make "segmentation" optional + for field in ["id", "image_id", "iscrowd", "category_id", "bbox"]: with self.subTest(field=field): with TestDir() as test_dir: ann_path = self._get_dummy_annotation_path(test_dir)