Skip to content

Commit 6b40bb9

Browse files
authored
Bugfix: inference would sometimes fail due to incorrect handling of empty label
* Implement new label management for prediction converters (implementation is now similar to how Geti manages labels). * Introduce improvements for converting semantic segmentation results (requires openvino-model-api==0.2.5.1)
1 parent fb735fe commit 6b40bb9

File tree

4 files changed

+225
-114
lines changed

4 files changed

+225
-114
lines changed

geti_sdk/deployment/deployed_model.py

+18-16
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import tempfile
2020
import time
2121
import zipfile
22+
from copy import deepcopy
2223
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
2324

2425
import attr
@@ -317,14 +318,7 @@ def load_inference_model(
317318
# Get label metadata from the project
318319
self._labels = LabelList.from_project(project=project, task_index=task_index)
319320

320-
# Load a Results-to-Prediction converter
321-
self._domain = Domain.from_task_type(
322-
project.get_trainable_tasks()[task_index].type
323-
)
324-
self._converter = ConverterFactory.create_converter(
325-
self.labels, configuration=configuration, domain=self._domain
326-
)
327-
model_api_configuration = self._clean_model_config(configuration)
321+
model_api_configuration = self._get_clean_model_config(configuration)
328322

329323
model = model_api_Model.create_model(
330324
model=model_adapter,
@@ -336,14 +330,20 @@ def load_inference_model(
336330

337331
self._inference_model = model
338332

333+
# Load a Results-to-Prediction converter
334+
self._domain = Domain.from_task_type(
335+
project.get_trainable_tasks()[task_index].type
336+
)
337+
self._converter = ConverterFactory.create_converter(
338+
self.labels, configuration=configuration, domain=self._domain, model=model
339+
)
340+
339341
# Extract tiling parameters, if applicable
340342
# OTX < 2.0: extract from config.json
341343
legacy_tiling_parameters = configuration_json.get("tiling_parameters", {})
342344
tiling_configuration = {}
343345

344-
enable_tiling = legacy_tiling_parameters.get("enable_tiling", {}).get(
345-
"value", False
346-
)
346+
enable_tiling = legacy_tiling_parameters.get("enable_tiling", False)
347347
if enable_tiling:
348348
try:
349349
tile_overlap = legacy_tiling_parameters["tile_overlap"]["value"]
@@ -829,13 +829,15 @@ def get_model_config(self) -> Dict[str, Any]:
829829
config[child.tag] = value
830830
return config
831831

832-
def _clean_model_config(self, configuration: Dict[str, Any]) -> Dict[str, Any]:
832+
@staticmethod
833+
def _get_clean_model_config(configuration: Dict[str, Any]) -> Dict[str, Any]:
833834
"""
834-
Remove unused values from the model configuration dictionary
835+
Return a copy of the model configurations with unused values removed.
835836
836837
:param configuration: Dictionary containing the model configuration to clean
837-
:return: Configuration dictionary with unused values removed
838+
:return: Copy of the configuration dictionary with unused values removed
838839
"""
840+
_config = deepcopy(configuration)
839841
unused_keys = [
840842
"label_ids",
841843
"label_info",
@@ -847,5 +849,5 @@ def _clean_model_config(self, configuration: Dict[str, Any]) -> Dict[str, Any]:
847849
"domain",
848850
]
849851
for key in unused_keys:
850-
configuration.pop(key, None)
851-
return configuration
852+
_config.pop(key, None)
853+
return _config

0 commit comments

Comments
 (0)