From 2b29450fe7845f9f751ecf6bf96dfa5122e0d3ff Mon Sep 17 00:00:00 2001 From: sooahleex Date: Fri, 8 Mar 2024 21:49:29 +0900 Subject: [PATCH 1/2] Fix components --- src/datumaro/components/comparator.py | 27 ++++++++++++------- src/datumaro/components/filter.py | 6 ++++- src/datumaro/components/visualizer.py | 4 ++- .../legacy/annotations/train.json | 2 +- tests/unit/data_formats/datumaro/conftest.py | 2 +- 5 files changed, 28 insertions(+), 13 deletions(-) diff --git a/src/datumaro/components/comparator.py b/src/datumaro/components/comparator.py index 295261f046..3d295e5404 100644 --- a/src/datumaro/components/comparator.py +++ b/src/datumaro/components/comparator.py @@ -1,4 +1,4 @@ -# Copyright (C) 2023 Intel Corporation +# Copyright (C) 2023-2024 Intel Corporation # # SPDX-License-Identifier: MIT @@ -604,7 +604,9 @@ def _create_low_level_comparison_table( return table, data_dict - def compare_datasets(self, first: Dataset, second: Dataset) -> Tuple[str, str, str, Dict]: + def compare_datasets( + self, first: Dataset, second: Dataset, mode: str = "all" + ) -> Tuple[str, str, str, Dict]: """Compares two datasets and generates comparison reports. Args: @@ -618,13 +620,20 @@ def compare_datasets(self, first: Dataset, second: Dataset) -> Tuple[str, str, s first_info = self._analyze_dataset(first) second_info = self._analyze_dataset(second) - high_level_table, high_level_dict = self._create_high_level_comparison_table( - first_info, second_info - ) - mid_level_table, mid_level_dict = self._create_mid_level_comparison_table( - first_info, second_info - ) - low_level_table, low_level_dict = self._create_low_level_comparison_table(first, second) + high_level_table, high_level_dict = None, {} + mid_level_table, mid_level_dict = None, {} + low_level_table, low_level_dict = None, {} + + if mode in ["high", "all"]: + high_level_table, high_level_dict = self._create_high_level_comparison_table( + first_info, second_info + ) + if mode in ["mid", "all"]: + mid_level_table, mid_level_dict = self._create_mid_level_comparison_table( + first_info, second_info + ) + if mode in ["low", "all"]: + low_level_table, low_level_dict = self._create_low_level_comparison_table(first, second) comparison_dict = dict( high_level=high_level_dict, mid_level=mid_level_dict, low_level=low_level_dict diff --git a/src/datumaro/components/filter.py b/src/datumaro/components/filter.py index f576aa1a20..9b828e3365 100644 --- a/src/datumaro/components/filter.py +++ b/src/datumaro/components/filter.py @@ -1,4 +1,4 @@ -# Copyright (C) 2019-2023 Intel Corporation +# Copyright (C) 2019-2024 Intel Corporation # # SPDX-License-Identifier: MIT from __future__ import annotations @@ -15,6 +15,7 @@ Bbox, Caption, Ellipse, + HashKey, Label, Mask, Points, @@ -257,6 +258,9 @@ def encode_annotation( return cls.encode_caption_object(o) if isinstance(o, Ellipse): return cls.encode_ellipse_object(o, categories) + if isinstance(o, HashKey): + return cls.encode_annotation_base(o) + raise NotImplementedError("Unexpected annotation object passed: %s" % o) @staticmethod diff --git a/src/datumaro/components/visualizer.py b/src/datumaro/components/visualizer.py index 7d44bcf8f4..7030165871 100644 --- a/src/datumaro/components/visualizer.py +++ b/src/datumaro/components/visualizer.py @@ -1,4 +1,4 @@ -# Copyright (C) 2023 Intel Corporation +# Copyright (C) 2024 Intel Corporation # # SPDX-License-Identifier: MIT from __future__ import annotations @@ -188,6 +188,8 @@ def _draw( return self._draw_depth_annotation(ann, label_categories, fig, ax, context) if ann.type == AnnotationType.ellipse: return self._draw_ellipse(ann, label_categories, fig, ax, context) + if ann.type == AnnotationType.hash_key: + return None # warning instead of raising an error for unsupported annotation types. log.warning(f"Ignore unknown ann.type={ann.type}") diff --git a/tests/assets/datumaro_dataset/legacy/annotations/train.json b/tests/assets/datumaro_dataset/legacy/annotations/train.json index ad51390b31..1a0d1e0bf2 100644 --- a/tests/assets/datumaro_dataset/legacy/annotations/train.json +++ b/tests/assets/datumaro_dataset/legacy/annotations/train.json @@ -94,7 +94,7 @@ "id": 3, "type": "label", "group": 0, - "label_id": 5 + "label_id": 3 } ], "image": { diff --git a/tests/unit/data_formats/datumaro/conftest.py b/tests/unit/data_formats/datumaro/conftest.py index 84786ad090..2a7fbafcd7 100644 --- a/tests/unit/data_formats/datumaro/conftest.py +++ b/tests/unit/data_formats/datumaro/conftest.py @@ -397,7 +397,7 @@ def fxt_legacy_dataset_pair(test_dir): Label(id=0, label=0), Label(id=1, label=1), Label(id=2, label=2), - Label(id=3, label=5), + Label(id=3, label=3), ], ), DatasetItem( From 41472d7ff7274d4b7436ae5dd867cc67ce6a8cf7 Mon Sep 17 00:00:00 2001 From: sooahleex Date: Fri, 8 Mar 2024 21:54:35 +0900 Subject: [PATCH 2/2] Update CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f4c14882c..8b2a514973 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 () - Enhance explore unit test to use real dataset from ImageNet () +- Fix each method of the comparator to be used separately + () ### Bug fixes - Fix wrong example of Datumaro dataset creation in document