f7a262ac9a
Build & push images / images (push) Successful in 6m31s
apps/trainer (parking-trainer): inspect / train / evaluate / publish. Reads the wash collector's SQLite + crops read-only off its volume; time split (validation = newest slice); thin classes dropped; damped class weights; `features` mode (frozen ImageNet backbone, on-disk feature cache, seconds to retrain) and `finetune` mode (light augmentation). CPU-only torch from PyTorch's wheel index. ONNX export checked against the torch model; NO model file below the validation floor (exit 3, report still written); exit 2 = not enough labels. `evaluate` scores a shipped model on labels reviewed after training + the unlabelled pile; `publish` PUTs a version folder to a Gitea generic package. Light core deps; the `train` extra is heavy — CI syncs without it, torch tests skip. apps/vision: BodyTypeClassifier (bodytype.onnx + sidecar = the preprocessing contract: crop margin, input size, RGB 0-255, normalisation inside the graph) and RefinedVehicleDetector over YOLOX — refines only `car` or a class the classifier trained on, min-confidence, `detector_class` on the result; path set but no file = phase B off without an error; a broken file is a health detail. models/bodytype.version (tracked, empty) pins the published version the Dockerfile fetches at build (BuildKit secret; a pin that cannot be fetched fails the build). Verified: a trainer model gives identical probabilities inside the vision service; both images built and smoke-tested. Delivery: parking-trainer image in build-images.yml, the `trainer` compose profile on the collector stack (CPU, read-only data, TRAINER_OUT), commented TRAINER_OUT/PUBLISH_TOKEN in the wash-collector stack, .dockerignore for both Python contexts, trainer deps synced in CI. Wiki: bodytype-classifier-training rewritten as built (+ one fleet model not per site, secrets/access, where the crops live), opencv-anpr-service §Phase B, vision-review-outbox, vision-service-packaging, fleet-deployment-komodo, index, log. Claude-Session: https://claude.ai/code/session_01FWncR69HgGPuei1dLrW3cU
56 lines
2.5 KiB
Python
56 lines
2.5 KiB
Python
"""Runtime configuration, from environment (prefix VISION_).
|
|
|
|
Offline-first: every default is local and works with no network. The recognizer is
|
|
chosen by `recognizer` — "stub" (no models, deterministic placeholder) or "fast_alpr"
|
|
(the real MIT YOLOv9+CCT/ONNX stack, installed via the `alpr` extra).
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Literal
|
|
|
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
model_config = SettingsConfigDict(env_prefix="VISION_", env_file=".env", extra="ignore")
|
|
|
|
host: str = "0.0.0.0"
|
|
port: int = 8089
|
|
|
|
# Which recognizer to load. "stub" needs no model weights (boots anywhere, for
|
|
# dev/CI); "fast_alpr" loads the real models (requires the `alpr` extra installed).
|
|
recognizer: Literal["stub", "fast_alpr"] = "stub"
|
|
|
|
# fast-alpr model names (only used when recognizer="fast_alpr"). Defaults match the
|
|
# library defaults; swap the OCR for the 40+country EU model to benchmark Albanian
|
|
# plates. See wiki/entities/opencv-anpr-service.md "Recognizer evaluation".
|
|
detector_model: str = "yolo-v9-t-384-license-plate-end2end"
|
|
ocr_model: str = "cct-xs-v2-global-model"
|
|
|
|
# Below this OCR confidence the read is returned but flagged low_confidence, so the
|
|
# Node side can fall back to the ticket path rather than trust it.
|
|
min_confidence: float = 0.5
|
|
|
|
# Vehicle stage (phase A — venue-modules.md §Vehicle category from vision): a YOLOX
|
|
# ONNX graph (Apache-2.0) run beside the plate recognizer. Unset = stage off (the
|
|
# response's `vehicle` stays null). Bake the file into the image (models/), never a
|
|
# path an operator can write (vision-service-hardening.md).
|
|
vehicle_model_path: str | None = None
|
|
vehicle_input_size: int = 640
|
|
# Detection score floor for a vehicle box to count at all (the Node side applies the
|
|
# site's own, stricter threshold before it FLAGS anything).
|
|
vehicle_min_confidence: float = 0.4
|
|
|
|
# Phase B — the body-type classifier on the detector's crop (bodytype.onnx + its .json
|
|
# sidecar, produced by apps/trainer, baked into the image when
|
|
# models/bodytype.version pins a published version). Path set but NO file = the normal
|
|
# state before the first model ships: the stage is simply off (logged, not an error).
|
|
vehicle_classifier_path: str | None = None
|
|
# Below this probability the classifier's answer is dropped and the detector's stands.
|
|
vehicle_classifier_min_confidence: float = 0.6
|
|
|
|
|
|
def get_settings() -> Settings:
|
|
return Settings()
|