Skip to content

Commit

Permalink
Fix h-label bug of missing parent labels in output (#2626)
Browse files Browse the repository at this point in the history
* 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 <songki.choi@intel.com>
  • Loading branch information
goodsong81 authored Nov 10, 2023
1 parent 6462a4b commit 2c9b745
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ All notable changes to this project will be documented in this file.
- Fix h-label loss normalization issue w/ exclusive label group of singe label (<https://github.com/openvinotoolkit/training_extensions/pull/2604>)
- Fix division by zero in class incremental learning for classification (<https://github.com/openvinotoolkit/training_extensions/pull/2606>)
- Fix saliency maps calculation issue for detection models (<https://github.com/openvinotoolkit/training_extensions/pull/2609>)
- Fix h-label bug of missing parent labels in output (<https://github.com/openvinotoolkit/training_extensions/pull/2626>)

## \[v1.4.3\]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ class OTXHierarchicalClsDataset(OTXMultilabelClsDataset):

def __init__(self, **kwargs):
self.hierarchical_info = kwargs.pop("hierarchical_info", None)
self.label_schema = kwargs.pop("label_schema", None)
super().__init__(**kwargs)

def load_annotations(self):
Expand All @@ -308,6 +309,13 @@ def load_annotations(self):
for i, _ in enumerate(self.otx_dataset):
class_indices = []
item_labels = self.otx_dataset[i].get_roi_labels(self.labels, include_empty=include_empty)
if self.label_schema:
# NOTE: Parent labels might be missing in annotations.
# This code fills the gap just in case.
full_item_labels = set()
for label in item_labels:
full_item_labels.update(self.label_schema.get_ancestors(label))
item_labels = full_item_labels
ignored_labels = self.otx_dataset[i].ignored_labels
if item_labels:
num_cls_heads = self.hierarchical_info["num_multiclass_heads"]
Expand Down
1 change: 1 addition & 0 deletions src/otx/algorithms/classification/adapters/mmcls/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ def configure(
elif self._hierarchical:
options_for_patch_datasets["type"] = "OTXHierarchicalClsDataset"
options_for_patch_datasets["hierarchical_info"] = self._hierarchical_info
options_for_patch_datasets["label_schema"] = self._task_environment.label_schema
options_for_patch_evaluation["task"] = "hierarchical"
elif self._selfsl:
options_for_patch_datasets["type"] = "SelfSLDataset"
Expand Down
5 changes: 5 additions & 0 deletions tests/assets/datumaro_h-label/annotations/train.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
"categories": {
"label": {
"label_groups": [
{
"name": "shape",
"group_type": "exclusive",
"labels": ["blue", "green"]
},
{
"name": "blue",
"group_type": "exclusive",
Expand Down
5 changes: 5 additions & 0 deletions tests/assets/datumaro_h-label/annotations/valid.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
"categories": {
"label": {
"label_groups": [
{
"name": "shape",
"group_type": "exclusive",
"labels": ["blue", "green"]
},
{
"name": "blue",
"group_type": "exclusive",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
"categories": {
"label": {
"label_groups": [
{
"name": "shape",
"group_type": "exclusive",
"labels": ["blue", "green"]
},
{
"name": "blue",
"group_type": "exclusive",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
"categories": {
"label": {
"label_groups": [
{
"name": "shape",
"group_type": "exclusive",
"labels": ["blue", "green"]
},
{
"name": "blue",
"group_type": "exclusive",
Expand Down

0 comments on commit 2c9b745

Please # to comment.