From 168ce9dac9cb7e5e3cde1b443dbe1e8665ac9b3d Mon Sep 17 00:00:00 2001 From: Vladisalv Sovrasov Date: Fri, 20 Dec 2024 01:52:19 +0900 Subject: [PATCH] Add extra check to export params --- src/otx/core/types/export.py | 5 +++++ tests/unit/core/types/test_export.py | 14 ++++++++++++++ 2 files changed, 19 insertions(+) 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..4e59cd38be 100644 --- a/tests/unit/core/types/test_export.py +++ b/tests/unit/core/types/test_export.py @@ -53,3 +53,17 @@ 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_wrap_label_consistency(fxt_label_info): + fxt_label_info.label_ids.append("new id") + print(fxt_label_info) + params = TaskLevelExportParameters( + model_type="dummy model", + task_type="instance_segmentation", + label_info=fxt_label_info, + optimization_config={}, + ) + + with pytest.raises(RuntimeError, match="incorrect"): + params.to_metadata()