Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor updates #4162

Merged
merged 6 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
14 changes: 14 additions & 0 deletions tests/unit/core/types/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Loading