Repository navigation
Expand file tree
/
Copy pathconfig.py
More file actions
90 lines (74 loc) · 4.27 KB
/
Copy pathconfig.py
File metadata and controls
90 lines (74 loc) · 4.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
from pydantic_settings import BaseSettings
from typing import List, Dict, Any, Optional, Tuple
class Settings(BaseSettings):
"""Application settings."""
# API settings
API_V1_STR: str = "/v1"
PROJECT_NAME: str = "Light Object Detection API"
# Backend settings
DEFAULT_BACKEND: str = "onnx"
AVAILABLE_BACKENDS: List[str] = ["onnx", "tflite", "opencv", "edgetpu", "moondream"]
# TFLite settings
TFLITE_MODEL_PATH: str = "backends/tflite/models/ssd_mobilenet_v1.tflite"
TFLITE_LABELS_PATH: str = "backends/tflite/models/labelmap.txt"
TFLITE_CONFIDENCE_THRESHOLD: float = 0.5
# ONNX settings
ONNX_MODEL_PATH: str = "backends/onnx/models/yolo26n-distill.onnx"
ONNX_LABELS_PATH: str = "backends/onnx/models/coco.txt"
ONNX_CONFIDENCE_THRESHOLD: float = 0.5
ONNX_IOU_THRESHOLD: float = 0.45
ONNX_MODEL_TYPE: str = "yolo26"
# Execution provider preference order, comma-separated. Accepts the short
# aliases 'cuda', 'openvino' and 'cpu' or full ONNX Runtime provider names.
# Providers missing from the installed wheel are skipped, so one value works
# across CUDA, OpenVINO and plain-CPU hosts; CPU is always the last resort.
ONNX_EXECUTION_PROVIDERS: str = "cuda,openvino,cpu"
# OpenVINO execution provider options. Only used when 'openvino' is selected
# and the onnxruntime-openvino wheel is installed — see BACKEND_CONFIGURATION.md.
# Unset values fall through to OpenVINO's own per-device defaults.
ONNX_OPENVINO_DEVICE_TYPE: str = "AUTO" # CPU, GPU, NPU, AUTO, or HETERO/MULTI/AUTO:<devices>
ONNX_OPENVINO_PRECISION: Optional[str] = None # FP32, FP16, ACCURACY
ONNX_OPENVINO_NUM_THREADS: Optional[int] = None
ONNX_OPENVINO_CACHE_DIR: Optional[str] = None # caches compiled blobs; big startup win on GPU/NPU
# OpenCV DNN settings
OPENCV_MODEL_PATH: str = "backends/opencv/models/yolov4-tiny.weights"
OPENCV_CONFIG_PATH: str = "backends/opencv/models/yolov4-tiny.cfg"
OPENCV_LABELS_PATH: str = "backends/opencv/models/coco.names"
OPENCV_CONFIDENCE_THRESHOLD: float = 0.5
OPENCV_NMS_THRESHOLD: float = 0.4
OPENCV_MODEL_TYPE: str = "yolo"
OPENCV_INPUT_SIZE: Tuple[int, int] = (416, 416)
# EdgeTPU (Coral) settings
EDGETPU_MODEL_PATH: str = "backends/edgetpu/models/ssd_mobilenet_v2_coco_quant_postprocess_edgetpu.tflite"
EDGETPU_LABELS_PATH: str = "backends/edgetpu/models/coco_labels.txt"
EDGETPU_CONFIDENCE_THRESHOLD: float = 0.5
EDGETPU_DEVICE: Optional[str] = None # None=auto, 'usb', 'usb:0', 'pci', 'pci:0'
EDGETPU_MODEL_TYPE: str = "ssd" # 'ssd' or 'yolo'
EDGETPU_IOU_THRESHOLD: float = 0.4 # For YOLO models only
# Moondream settings (local HuggingFace Transformers inference)
MOONDREAM_MODEL_NAME: str = "vikhyatk/moondream2"
MOONDREAM_REVISION: Optional[str] = None # pin a specific model revision
MOONDREAM_DEVICE: str = "cpu" # "cpu", "cuda", "mps"
MOONDREAM_DEFAULT_DETECT_CLASSES: List[str] = [
"person", "car", "truck", "bicycle", "motorcycle", "bus",
"dog", "cat", "bird", "horse",
]
# Image settings
MAX_IMAGE_SIZE: int = 1024 # Maximum dimension (width or height) in pixels
# Detection keeps full resolution: the backend letterboxes to model input anyway,
# so an intermediate downscale only costs small objects. This is a sanity ceiling
# against absurd uploads, not a working limit — it should sit far above any real frame.
MAX_DETECTION_IMAGE_SIZE: int = 8192
SUPPORTED_FORMATS: List[str] = ["jpg", "jpeg", "png"]
# Tiled detection defaults (see utils/tiling.py). All are overridable per-request
# via query params on /v1/detect, which is how lightNVR configures them per stream.
TILE_BUDGET: int = 1 # T: inferences per request; 1 disables tiling
TILE_MIN_OBJECT_PX: int = 60 # smallest object to resolve, in source pixels
TILE_OVERLAP: float = 0.25 # fraction of tile size overlapped with neighbours
TILE_PERIOD_SECONDS: float = 1.0 # rotation cursor period; match detection_interval
TILE_DEADLINE_SECONDS: float = 7.0 # stop issuing tiles at this elapsed time
TILE_IOU_THRESHOLD: float = 0.45 # cross-tile NMS threshold
class Config:
env_file = ".env"
case_sensitive = True
settings = Settings()