From 0c3cd2f7eb069906c67b72fdfafb8085af010960 Mon Sep 17 00:00:00 2001 From: Vladislav Sovrasov Date: Fri, 20 Dec 2024 15:22:33 +0100 Subject: [PATCH] Minor updates (#4162) * 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 --- CHANGELOG.md | 2 ++ pyproject.toml | 6 +++--- src/otx/core/data/dataset/segmentation.py | 1 + src/otx/core/model/instance_segmentation.py | 2 ++ src/otx/core/model/segmentation.py | 1 + src/otx/core/types/export.py | 5 +++++ tests/unit/core/types/test_export.py | 17 +++++++++++++++++ 7 files changed, 31 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f6573d58f3..965a0b761c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,8 @@ All notable changes to this project will be documented in this file. () - Add mAP metric to evaluate multilabel classification () +- Bump OV to 2024.6, update empty label handling + () ### Bug fixes diff --git a/pyproject.toml b/pyproject.toml index c98c6b4d41..4b279fe9c5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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", ] diff --git a/src/otx/core/data/dataset/segmentation.py b/src/otx/core/data/dataset/segmentation.py index 5672989e7f..8f9d8f8fe7 100644 --- a/src/otx/core/data/dataset/segmentation.py +++ b/src/otx/core/data/dataset/segmentation.py @@ -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, diff --git a/src/otx/core/model/instance_segmentation.py b/src/otx/core/model/instance_segmentation.py index 60b7079230..5c7afbcef3 100644 --- a/src/otx/core/model/instance_segmentation.py +++ b/src/otx/core/model/instance_segmentation.py @@ -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", @@ -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 diff --git a/src/otx/core/model/segmentation.py b/src/otx/core/model/segmentation.py index eeebba408f..c84063ae80 100644 --- a/src/otx/core/model/segmentation.py +++ b/src/otx/core/model/segmentation.py @@ -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 diff --git a/src/otx/core/types/export.py b/src/otx/core/types/export.py index fc35a39b8f..a8a511355a 100644 --- a/src/otx/core/types/export.py +++ b/src/otx/core/types/export.py @@ -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: diff --git a/tests/unit/core/types/test_export.py b/tests/unit/core/types/test_export.py index 70a4aa1aa2..6e154863da 100644 --- a/tests/unit/core/types/test_export.py +++ b/tests/unit/core/types/test_export.py @@ -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 @@ -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()