Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix each method of the comparator to be used separately #1290

Merged
merged 2 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
(<https://github.com/openvinotoolkit/datumaro/pull/1263>)
- Enhance explore unit test to use real dataset from ImageNet
(<https://github.com/openvinotoolkit/datumaro/pull/1266>)
- Fix each method of the comparator to be used separately
(<https://github.com/openvinotoolkit/datumaro/pull/1290>)

### Bug fixes
- Fix wrong example of Datumaro dataset creation in document
Expand Down
27 changes: 18 additions & 9 deletions src/datumaro/components/comparator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2023 Intel Corporation
# Copyright (C) 2023-2024 Intel Corporation
#
# SPDX-License-Identifier: MIT

Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/datumaro/components/filter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2019-2023 Intel Corporation
# Copyright (C) 2019-2024 Intel Corporation
#
# SPDX-License-Identifier: MIT
from __future__ import annotations
Expand All @@ -15,6 +15,7 @@
Bbox,
Caption,
Ellipse,
HashKey,
Label,
Mask,
Points,
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/datumaro/components/visualizer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2023 Intel Corporation
# Copyright (C) 2024 Intel Corporation
#
# SPDX-License-Identifier: MIT
from __future__ import annotations
Expand Down Expand Up @@ -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}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
"id": 3,
"type": "label",
"group": 0,
"label_id": 5
"label_id": 3
}
],
"image": {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/data_formats/datumaro/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading