Skip to content

Commit

Permalink
Minor updates (#4162)
Browse files Browse the repository at this point in the history
* Bump OV and NNCF

* Update iseg empty label handling

* Update bg label handling in sseg

* Update changelog

* Add extra check to export params

* Update test case implementation
  • Loading branch information
sovrasov authored Dec 20, 2024
1 parent 8a82764 commit 0c3cd2f
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ All notable changes to this project will be documented in this file.
(<https://github.com/openvinotoolkit/training_extensions/pull/3843>)
- Add mAP metric to evaluate multilabel classification
(<https://github.com/openvinotoolkit/training_extensions/pull/3985>)
- Bump OV to 2024.6, update empty label handling
(<https://github.com/openvinotoolkit/training_extensions/pull/4162>)

### Bug fixes

Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ base = [
"lightning==2.4.0",
"pytorchcv==0.0.67",
"timm==1.0.3",
"openvino==2024.5",
"openvino-dev==2024.5",
"openvino==2024.6",
"openvino-dev==2024.6",
"openvino-model-api==0.2.5",
"onnx==1.17.0",
"onnxconverter-common==1.14.0",
"nncf==2.14.0",
"nncf==2.14.1",
"anomalib[core]==1.1.0",
]

Expand Down
1 change: 1 addition & 0 deletions src/otx/core/data/dataset/segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ def __init__(
if self.has_polygons:
# insert background class at index 0 since polygons represent only objects
self.label_info.label_names.insert(0, "otx_background_lbl")
self.label_info.label_ids.insert(0, "None")

self.label_info = SegLabelInfo(
label_names=self.label_info.label_names,
Expand Down
2 changes: 2 additions & 0 deletions src/otx/core/model/instance_segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ def _export_parameters(self) -> TaskLevelExportParameters:
modified_label_info = copy.deepcopy(self.label_info)
# Instance segmentation needs to add empty label to satisfy MAPI wrapper requirements
modified_label_info.label_names.insert(0, "otx_empty_lbl")
modified_label_info.label_ids.insert(0, "None")

return super()._export_parameters.wrap(
model_type="MaskRCNN",
Expand Down Expand Up @@ -773,6 +774,7 @@ def _create_label_info_from_ov_ir(self) -> LabelInfo:
# workaround to hide extra otx_empty_lbl
if ir_label_info.label_names[0] == "otx_empty_lbl":
ir_label_info.label_names.pop(0)
ir_label_info.label_ids.pop(0)
ir_label_info.label_groups[0].pop(0)
return ir_label_info

Expand Down
1 change: 1 addition & 0 deletions src/otx/core/model/segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ def _export_parameters(self) -> TaskLevelExportParameters:
# remove otx background label for export
modified_label_info = copy.deepcopy(self.label_info)
modified_label_info.label_names.pop(0)
modified_label_info.label_ids.pop(0)
else:
modified_label_info = self.label_info

Expand Down
5 changes: 5 additions & 0 deletions src/otx/core/types/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ def to_metadata(self) -> dict[tuple[str, str], str]:
"""
all_labels = ""
all_label_ids = ""

if len(self.label_info.label_names) != len(self.label_info.label_ids):
msg = "Label info is incorrect: label names and IDs do not match"
raise RuntimeError(msg)

for lbl in self.label_info.label_names:
all_labels += lbl.replace(" ", "_") + " "
for lbl_id in self.label_info.label_ids:
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/core/types/test_export.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

from copy import deepcopy

import pytest
from otx.core.config.data import TileConfig
from otx.core.types.export import TaskLevelExportParameters
Expand Down Expand Up @@ -53,3 +55,18 @@ def test_wrap(fxt_label_info, task_type):
assert ("model_info", "tiles_overlap") in metadata
assert ("model_info", "max_pred_number") in metadata
assert ("model_info", "otx_version") in metadata


def test_to_metadata_label_consistency(fxt_label_info):
label_info = deepcopy(fxt_label_info)
label_info.label_ids.append("new id")

params = TaskLevelExportParameters(
model_type="dummy model",
task_type="instance_segmentation",
label_info=label_info,
optimization_config={},
)

with pytest.raises(RuntimeError, match="incorrect"):
params.to_metadata()

0 comments on commit 0c3cd2f

Please sign in to comment.