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:
+18
-21
@@ -8,9 +8,6 @@ from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass, field
|
||||
|
||||
DETECTORS = ("yolo",)
|
||||
RESTORERS = ("deepmosaics", "deepmosaics_video")
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class DetectionConfig:
|
||||
@@ -25,15 +22,26 @@ class DetectionConfig:
|
||||
class OverlayConfig:
|
||||
"""How detections are drawn over the image."""
|
||||
|
||||
# RGB per CensorType value
|
||||
# RGB per detection category/label (the models/yolo/<category> folder name, or the
|
||||
# CensorType for legacy detections). Unknown categories get a stable palette colour.
|
||||
colors: dict[str, tuple[int, int, int]] = field(
|
||||
default_factory=lambda: {
|
||||
"mosaic": (231, 76, 60), # red
|
||||
"blur": (241, 196, 15), # yellow
|
||||
"mosaic": (231, 76, 60), # red
|
||||
"blur": (241, 196, 15), # yellow
|
||||
"black_bar": (26, 188, 156), # teal
|
||||
"unknown": (155, 89, 182), # purple
|
||||
"unknown": (155, 89, 182), # purple
|
||||
"face": (46, 204, 113), # green
|
||||
"hand": (52, 152, 219), # blue
|
||||
"person": (230, 126, 34), # orange
|
||||
"eyes": (155, 89, 182), # purple
|
||||
"text": (149, 165, 166), # grey
|
||||
}
|
||||
)
|
||||
# Fallback colours cycled (deterministically) for categories not listed above.
|
||||
palette: tuple[tuple[int, int, int], ...] = (
|
||||
(231, 76, 60), (46, 204, 113), (52, 152, 219), (241, 196, 15),
|
||||
(155, 89, 182), (26, 188, 156), (230, 126, 34), (149, 165, 166),
|
||||
)
|
||||
line_width: int = 2
|
||||
fill_alpha: int = 48 # 0..255 translucency of the region fill
|
||||
show_labels: bool = True
|
||||
@@ -44,7 +52,9 @@ class AppConfig:
|
||||
detection: DetectionConfig = field(default_factory=DetectionConfig)
|
||||
overlay: OverlayConfig = field(default_factory=OverlayConfig)
|
||||
detector: str = "yolo" # only "yolo"
|
||||
model_path: str | None = None # weights path, used by the YOLO detector
|
||||
# Active YOLO models (paths under models/yolo/<category>/). A detect runs every
|
||||
# selected model and merges results — see core/detection/multi.MultiYoloDetector.
|
||||
detector_models: list[str] = field(default_factory=list)
|
||||
default_threshold: float = 0.20 # initial overlay confidence threshold
|
||||
|
||||
# --- restoration ("расцензурить") ---
|
||||
@@ -52,16 +62,3 @@ class AppConfig:
|
||||
dm_dir: str | None = None # optional extra dir to search for mosaic_position.pth
|
||||
dm_model: str | None = None # DeepMosaics clean weights (clean_*.pth)
|
||||
dm_gpu: str = "0" # CUDA device id, "-1" for CPU
|
||||
|
||||
|
||||
def normalize_config(cfg: AppConfig) -> None:
|
||||
"""Coerce legacy/removed settings to supported values (mutates ``cfg``).
|
||||
|
||||
Old projects / settings.json may carry the removed ``classic``/``combined``
|
||||
detectors or the ``inpaint`` restorer — map those onto the survivors so loading
|
||||
them doesn't blow up at build time.
|
||||
"""
|
||||
if cfg.detector not in DETECTORS:
|
||||
cfg.detector = "yolo"
|
||||
if cfg.restorer not in RESTORERS:
|
||||
cfg.restorer = "deepmosaics"
|
||||
|
||||
Reference in New Issue
Block a user