Skip to content

Commit 9b61a3e

Browse files
committed
Preserve DLC config using model_copy
Initialize an existing DLC config (falling back to DEFAULT_CONFIG if unset) and use its model_copy(update=...) to return settings. This replaces explicit field-by-field construction so only model_path (and model_type when set) are changed, preserving other DLC options and avoiding duplication.
1 parent 4dd3b4d commit 9b61a3e

1 file changed

Lines changed: 20 additions & 18 deletions

File tree

‎dlclivegui/gui/main_window.py‎

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -883,19 +883,23 @@ def _dlc_settings_from_ui(self, *, allow_empty_model_path=False) -> DLCProcessor
883883
# IMPORTANT NOTE: DLClive expects a directory for TensorFlow models,
884884
# so if user selects a .pb file, we should pass the parent directory to DLCLive
885885
model_path = str(Path(model_path).parent)
886+
887+
existing_dlc = ( # explicitly init from default if unset
888+
self._config.dlc.model_copy(deep=True)
889+
if getattr(self._config, "dlc", None) is not None
890+
else DEFAULT_CONFIG.dlc.model_copy(deep=True)
891+
)
886892
if not model_path:
887893
if allow_empty_model_path:
888-
return DLCProcessorSettings(
889-
model_path="",
890-
model_directory=self._config.dlc.model_directory, # Preserve from config
891-
device=self._config.dlc.device, # Preserve from config
892-
dynamic=self._config.dlc.dynamic, # Preserve from config
893-
resize=self._config.dlc.resize, # Preserve from config
894-
precision=self._config.dlc.precision, # Preserve from config
895-
model_type=None,
896-
# additional_options=self._parse_json(self.additional_options_edit.toPlainText()),
894+
# Preserve all existing DLC settings and only clear the model path.
895+
return existing_dlc.model_copy(
896+
update={
897+
"model_path": "",
898+
}
897899
)
900+
898901
raise ValueError("Model path cannot be empty. Please enter a valid path to a DLCLive model file.")
902+
899903
try:
900904
model_bknd = DLCLiveProcessor.get_model_backend(model_path)
901905
except Exception as e:
@@ -904,15 +908,13 @@ def _dlc_settings_from_ui(self, *, allow_empty_model_path=False) -> DLCProcessor
904908
"Please ensure the model file is valid and has an appropriate extension "
905909
"(.pt, .pth for PyTorch or model directory for TensorFlow)."
906910
) from e
907-
return DLCProcessorSettings(
908-
model_path=model_path,
909-
model_directory=self._config.dlc.model_directory, # Preserve from config
910-
device=self._config.dlc.device, # Preserve from config
911-
dynamic=self._config.dlc.dynamic, # Preserve from config
912-
resize=self._config.dlc.resize, # Preserve from config
913-
precision=self._config.dlc.precision, # Preserve from config
914-
model_type=model_bknd,
915-
# additional_options=self._parse_json(self.additional_options_edit.toPlainText()),
911+
912+
# Preserve all unchanged DLC settings and only update values derived from the UI.
913+
return existing_dlc.model_copy(
914+
update={
915+
"model_path": model_path,
916+
"model_type": model_bknd,
917+
}
916918
)
917919

918920
def _recording_settings_from_ui(self) -> RecordingSettings:

0 commit comments

Comments
 (0)