Implement multi-model detection in HVideoTool: updated the detection system to support multiple YOLO models simultaneously, enhancing detection capabilities. Reflected changes in the UI with a new model selection menu and updated documentation in README and CLAUDE.md to guide users on model management and configuration.

This commit is contained in:
Leonid Pershin
2026-06-07 07:05:50 +03:00
parent ac02ca27a8
commit 0996ca7bb9
14 changed files with 353 additions and 156 deletions
+20 -13
View File
@@ -4,26 +4,33 @@ Kept separate from ``app.py`` so both the app bootstrap and the UI can build
detectors without an import cycle. Raises ``ValueError`` (not ``SystemExit``) on
bad config so the GUI can show the message instead of exiting.
Only the YOLO detector is supported — the classic-CV heuristic (and the composite
mode that combined them) were removed: they were noisy/approximate on real footage.
YOLO-only, but multi-model: every path in ``config.detector_models`` (ticked under
models/yolo/<category>/) becomes a YoloDetector tagged with its category, and they
run together via :class:`~.multi.MultiYoloDetector`. The classic-CV detector and the
``combined`` composite were removed (noisy/approximate on real footage).
"""
from __future__ import annotations
from pathlib import Path
from ...config import AppConfig
from .base import Detector
def _require_model(config: AppConfig) -> str:
if not config.model_path:
raise ValueError(
"Для детектора YOLO укажите путь к весам (.pt) в Параметрах "
"или скачайте модель LADA — см. README."
)
return config.model_path
from .registry import category_of
def build_detector(config: AppConfig) -> Detector:
from .yolo import YoloDetector # lazy: pulls torch/ultralytics
models = [m for m in config.detector_models if Path(m).is_file()]
if not models:
raise ValueError(
"Не выбрана ни одна модель детекции.\n"
"Положите веса YOLO в models/yolo/<категория>/ (например models/yolo/mosaic/) "
"и отметьте их галочкой в меню «Модели». См. README."
)
# lazy imports: YoloDetector pulls in torch/ultralytics only when a detect runs
from .multi import MultiYoloDetector
from .yolo import YoloDetector
return YoloDetector(_require_model(config), config.detection)
return MultiYoloDetector([
YoloDetector(m, config.detection, label=category_of(m)) for m in models
])