Skip to content

Commit 2c9b745

Browse files
author
Songki Choi
authored
Fix h-label bug of missing parent labels in output (#2626)
* Fix h-label bug of missing parent labels in output * Fix h-label test data label schema * Update CHANGELOG.md --------- Signed-off-by: Songki Choi <[email protected]>
1 parent 6462a4b commit 2c9b745

File tree

7 files changed

+30
-0
lines changed

7 files changed

+30
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ All notable changes to this project will be documented in this file.
1717
- Fix h-label loss normalization issue w/ exclusive label group of singe label (<https://github.com/openvinotoolkit/training_extensions/pull/2604>)
1818
- Fix division by zero in class incremental learning for classification (<https://github.com/openvinotoolkit/training_extensions/pull/2606>)
1919
- Fix saliency maps calculation issue for detection models (<https://github.com/openvinotoolkit/training_extensions/pull/2609>)
20+
- Fix h-label bug of missing parent labels in output (<https://github.com/openvinotoolkit/training_extensions/pull/2626>)
2021

2122
## \[v1.4.3\]
2223

src/otx/algorithms/classification/adapters/mmcls/datasets/otx_datasets.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ class OTXHierarchicalClsDataset(OTXMultilabelClsDataset):
300300

301301
def __init__(self, **kwargs):
302302
self.hierarchical_info = kwargs.pop("hierarchical_info", None)
303+
self.label_schema = kwargs.pop("label_schema", None)
303304
super().__init__(**kwargs)
304305

305306
def load_annotations(self):
@@ -308,6 +309,13 @@ def load_annotations(self):
308309
for i, _ in enumerate(self.otx_dataset):
309310
class_indices = []
310311
item_labels = self.otx_dataset[i].get_roi_labels(self.labels, include_empty=include_empty)
312+
if self.label_schema:
313+
# NOTE: Parent labels might be missing in annotations.
314+
# This code fills the gap just in case.
315+
full_item_labels = set()
316+
for label in item_labels:
317+
full_item_labels.update(self.label_schema.get_ancestors(label))
318+
item_labels = full_item_labels
311319
ignored_labels = self.otx_dataset[i].ignored_labels
312320
if item_labels:
313321
num_cls_heads = self.hierarchical_info["num_multiclass_heads"]

src/otx/algorithms/classification/adapters/mmcls/task.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ def configure(
190190
elif self._hierarchical:
191191
options_for_patch_datasets["type"] = "OTXHierarchicalClsDataset"
192192
options_for_patch_datasets["hierarchical_info"] = self._hierarchical_info
193+
options_for_patch_datasets["label_schema"] = self._task_environment.label_schema
193194
options_for_patch_evaluation["task"] = "hierarchical"
194195
elif self._selfsl:
195196
options_for_patch_datasets["type"] = "SelfSLDataset"

tests/assets/datumaro_h-label/annotations/train.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
"categories": {
44
"label": {
55
"label_groups": [
6+
{
7+
"name": "shape",
8+
"group_type": "exclusive",
9+
"labels": ["blue", "green"]
10+
},
611
{
712
"name": "blue",
813
"group_type": "exclusive",

tests/assets/datumaro_h-label/annotations/valid.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
"categories": {
44
"label": {
55
"label_groups": [
6+
{
7+
"name": "shape",
8+
"group_type": "exclusive",
9+
"labels": ["blue", "green"]
10+
},
611
{
712
"name": "blue",
813
"group_type": "exclusive",

tests/assets/datumaro_h-label_class_decremental/annotations/train.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
"categories": {
44
"label": {
55
"label_groups": [
6+
{
7+
"name": "shape",
8+
"group_type": "exclusive",
9+
"labels": ["blue", "green"]
10+
},
611
{
712
"name": "blue",
813
"group_type": "exclusive",

tests/assets/datumaro_h-label_class_decremental/annotations/valid.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
"categories": {
44
"label": {
55
"label_groups": [
6+
{
7+
"name": "shape",
8+
"group_type": "exclusive",
9+
"labels": ["blue", "green"]
10+
},
611
{
712
"name": "blue",
813
"group_type": "exclusive",

0 commit comments

Comments
 (0)