Introduce the app/services/vision/ module with ABC interfaces, ONNX Runtime backend, model registry, and per-task implementations: - OpenCLIP ViT-B/32 embedder (image + text, 512-d) - RapidOCR engine (PP-OCRv4 via ONNX, no PaddlePaddle) - YOLOv8n object detector (raw ONNX, no ultralytics runtime) - YuNet + SFace face processor (Apache 2.0, opencv_zoo, 128-d) - DBSCAN face clustering helper Add VisionSettings to config (mulita.yml + Pydantic), bootstrap_models.py for first-boot weight downloads, models_data Docker volume, and ROCm backend stub for future GPU acceleration. No Celery tasks wired yet — models load but nothing invokes them. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
38 lines
1.3 KiB
Python
38 lines
1.3 KiB
Python
"""
|
|
ONNX Runtime backend — default CPU inference for all vision models.
|
|
|
|
Each create_* method returns a concrete implementation of the
|
|
corresponding ABC from base.py. Models are loaded from ONNX files
|
|
under settings.vision.models_dir, downloaded on first boot by
|
|
bootstrap_models.py.
|
|
"""
|
|
import logging
|
|
|
|
from app.config import VisionSettings
|
|
from app.services.vision.base import Embedder, OCREngine, ObjectDetector, FaceProcessor
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class ONNXBackend:
|
|
"""Factory for ONNX Runtime-based vision model instances."""
|
|
|
|
def __init__(self, vision_settings: VisionSettings):
|
|
self._settings = vision_settings
|
|
|
|
def create_embedder(self) -> Embedder:
|
|
from app.services.vision.embed import OpenCLIPEmbedder
|
|
return OpenCLIPEmbedder(self._settings)
|
|
|
|
def create_ocr(self) -> OCREngine:
|
|
from app.services.vision.ocr import RapidOCREngine
|
|
return RapidOCREngine(self._settings)
|
|
|
|
def create_detector(self) -> ObjectDetector:
|
|
from app.services.vision.detect import YOLOv8Detector
|
|
return YOLOv8Detector(self._settings)
|
|
|
|
def create_face_processor(self) -> FaceProcessor:
|
|
from app.services.vision.faces import YuNetSFaceProcessor
|
|
return YuNetSFaceProcessor(self._settings)
|