"""Ultralytics YOLO detector. Wraps an Ultralytics YOLO model (detection or segmentation) behind the :class:`Detector` interface. Designed for the LADA mosaic-detection weights (https://huggingface.co/ladaapp/lada), which are YOLO *segmentation* models with a single ``mosaic`` class — but it works with any Ultralytics ``.pt`` whose class names map onto :class:`CensorType`. Heavy imports (``ultralytics``/``torch``) happen lazily in ``__init__`` so the rest of the app never pulls them in until detection actually runs. Licensing: Ultralytics YOLO and the LADA weights are AGPL-3.0. See README. """ from __future__ import annotations import os from ...config import DetectionConfig from ..video.frame import Frame from .base import Detector from .types import CensorType, Detection def _name_to_type(name: str) -> CensorType: n = name.lower() if "mosaic" in n or "pixel" in n: return CensorType.MOSAIC if "blur" in n: return CensorType.BLUR if "bar" in n or "black" in n: return CensorType.BLACK_BAR return CensorType.UNKNOWN class YoloDetector(Detector): def __init__( self, model_path: str, config: DetectionConfig | None = None, label: str = "" ) -> None: self.cfg = config or DetectionConfig() self._label = label # category (models/yolo/