Skip to content

Commit 1bb70c7

Browse files
committed
Infer model backend from selected model path
Replace the hardcoded 'pytorch' model_type with a value inferred from the selected model file. main_window.py now reads the model_path into a local variable and uses DLCLiveProcessor.get_model_backend(model_path) when building DLCProcessorSettings. dlc_processor.py imports Engine from dlclive and adds a static get_model_backend method that returns Engine.from_model_path(model_path).value. Preserves existing config fields and error handling.
1 parent da3a363 commit 1bb70c7

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

dlclivegui/gui/main_window.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -875,14 +875,15 @@ def _parse_json(self, value: str) -> dict:
875875
return json.loads(text)
876876

877877
def _dlc_settings_from_ui(self) -> DLCProcessorSettings:
878+
model_path = self.model_path_edit.text().strip()
878879
return DLCProcessorSettings(
879-
model_path=self.model_path_edit.text().strip(),
880+
model_path=model_path,
880881
model_directory=self._config.dlc.model_directory, # Preserve from config
881882
device=self._config.dlc.device, # Preserve from config
882883
dynamic=self._config.dlc.dynamic, # Preserve from config
883884
resize=self._config.dlc.resize, # Preserve from config
884885
precision=self._config.dlc.precision, # Preserve from config
885-
model_type="pytorch", # FIXME @C-Achard hardcoded for now, we should allow tf models too
886+
model_type=DLCLiveProcessor.get_model_backend(model_path),
886887
# additional_options=self._parse_json(self.additional_options_edit.toPlainText()),
887888
)
888889

dlclivegui/services/dlc_processor.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@
2626
ENABLE_PROFILING = True
2727

2828
try: # pragma: no cover - optional dependency
29-
from dlclive import DLCLive # type: ignore
29+
from dlclive import (
30+
DLCLive, # type: ignore
31+
Engine, # type: ignore
32+
)
3033
except Exception as e: # pragma: no cover - handled gracefully
3134
logger.error(f"dlclive package could not be imported: {e}")
3235
DLCLive = None # type: ignore[assignment]
@@ -96,6 +99,10 @@ def __init__(self) -> None:
9699
self._gpu_inference_times: deque[float] = deque(maxlen=60)
97100
self._processor_overhead_times: deque[float] = deque(maxlen=60)
98101

102+
@staticmethod
103+
def get_model_backend(model_path: str) -> str:
104+
return Engine.from_model_path(model_path).value
105+
99106
def configure(self, settings: DLCProcessorSettings, processor: Any | None = None) -> None:
100107
self._settings = settings
101108
self._processor = processor

0 commit comments

Comments
 (0)