19
19
import tempfile
20
20
import time
21
21
import zipfile
22
+ from copy import deepcopy
22
23
from typing import Any , Callable , Dict , List , Optional , Tuple , Union
23
24
24
25
import attr
@@ -317,14 +318,7 @@ def load_inference_model(
317
318
# Get label metadata from the project
318
319
self ._labels = LabelList .from_project (project = project , task_index = task_index )
319
320
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 )
328
322
329
323
model = model_api_Model .create_model (
330
324
model = model_adapter ,
@@ -336,14 +330,20 @@ def load_inference_model(
336
330
337
331
self ._inference_model = model
338
332
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
+
339
341
# Extract tiling parameters, if applicable
340
342
# OTX < 2.0: extract from config.json
341
343
legacy_tiling_parameters = configuration_json .get ("tiling_parameters" , {})
342
344
tiling_configuration = {}
343
345
344
- enable_tiling = legacy_tiling_parameters .get ("enable_tiling" , {}).get (
345
- "value" , False
346
- )
346
+ enable_tiling = legacy_tiling_parameters .get ("enable_tiling" , False )
347
347
if enable_tiling :
348
348
try :
349
349
tile_overlap = legacy_tiling_parameters ["tile_overlap" ]["value" ]
@@ -829,13 +829,15 @@ def get_model_config(self) -> Dict[str, Any]:
829
829
config [child .tag ] = value
830
830
return config
831
831
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 ]:
833
834
"""
834
- Remove unused values from the model configuration dictionary
835
+ Return a copy of the model configurations with unused values removed.
835
836
836
837
: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
838
839
"""
840
+ _config = deepcopy (configuration )
839
841
unused_keys = [
840
842
"label_ids" ,
841
843
"label_info" ,
@@ -847,5 +849,5 @@ def _clean_model_config(self, configuration: Dict[str, Any]) -> Dict[str, Any]:
847
849
"domain" ,
848
850
]
849
851
for key in unused_keys :
850
- configuration .pop (key , None )
851
- return configuration
852
+ _config .pop (key , None )
853
+ return _config
0 commit comments