Skip to content

Commit b39f438

Browse files
committed
fix(desktop): resolve project models from packaged app
1 parent 95827be commit b39f438

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

app/core/inference.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from app.core.config import SpecialistModelConfig
99
from app.core.events import Detection
1010
from app.utils.logging import logger
11-
from app.utils.paths import resource_path
11+
from app.utils.paths import resolve_data_path, resource_path
1212

1313
YOLO_SPECIALIST_SOURCE = "YOLO specialist"
1414

@@ -209,11 +209,10 @@ def update_thresholds(self, conf=None, iou=None):
209209

210210
def _resolve_model_path(model_path: str | Path) -> Path:
211211
path = Path(model_path)
212-
if path.exists():
213-
return path
214-
bundled = resource_path(path)
215-
if bundled.exists():
216-
return bundled
212+
candidates = (path, resource_path(path), resolve_data_path(path))
213+
for candidate in candidates:
214+
if candidate.exists() and candidate.is_file():
215+
return candidate
217216
raise FileNotFoundError(f"model not found: {model_path}")
218217

219218

tests/unit/test_yolo_specialist.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from typing import ClassVar
22

3+
import app.core.inference as inference_module
34
from app.core.config import SpecialistModelConfig
45
from app.core.events import Detection
56
from app.core.inference import (
@@ -119,3 +120,14 @@ def __init__(self, _path: str) -> None:
119120
assert engine.class_names == {0: "Aerosols", 1: "Aluminum can"}
120121
assert engine._specialist_class_names == {0: "Pen", 1: "Battery"}
121122
assert engine._specialist_class_ids == [0, 1]
123+
124+
125+
def test_model_path_falls_back_to_project_data_for_desktop_shortcut(tmp_path, monkeypatch):
126+
model_path = tmp_path / "models" / "real-camera.pt"
127+
model_path.parent.mkdir()
128+
model_path.write_bytes(b"stub")
129+
130+
monkeypatch.setattr(inference_module, "resource_path", lambda _path: tmp_path / "bundle-missing")
131+
monkeypatch.setattr(inference_module, "resolve_data_path", lambda _path: model_path)
132+
133+
assert inference_module._resolve_model_path("models/real-camera.pt") == model_path

0 commit comments

Comments
 (0)