Compare commits

...
1 Commits
Author SHA1 Message Date
Nicolas Mowen ede06d794d Implement multi-model object detection 2026-07-23 17:51:21 -06:00
49 changed files with 1070 additions and 473 deletions
+236 -212
View File
@@ -34,12 +34,13 @@ edgeTPU:
type: edgetpu type: edgetpu
device: usb device: usb
model: models:
model_type: yolo-generic default:
width: 320 # <--- should match the imgsize of the model, typically 320 model_type: yolo-generic
height: 320 # <--- should match the imgsize of the model, typically 320 width: 320 # <--- should match the imgsize of the model, typically 320
path: /config/model_cache/yolov9-s-relu6-best_320_int8_edgetpu.tflite height: 320 # <--- should match the imgsize of the model, typically 320
labelmap_path: /config/labels-coco17.txt path: /config/model_cache/yolov9-s-relu6-best_320_int8_edgetpu.tflite
labelmap_path: /config/labels-coco17.txt
hailo8l: hailo8l:
title: Hailo-8/Hailo-8L title: Hailo-8/Hailo-8L
models: models:
@@ -67,27 +68,28 @@ hailo8l:
type: hailo8l type: hailo8l
device: PCIe device: PCIe
model: models:
width: 320 default:
height: 320 width: 320
input_tensor: nhwc height: 320
input_pixel_format: rgb input_tensor: nhwc
input_dtype: int input_pixel_format: rgb
model_type: yolo-generic input_dtype: int
labelmap_path: /labelmap/coco-80.txt model_type: yolo-generic
labelmap_path: /labelmap/coco-80.txt
# The detector automatically selects the default model based on your hardware: # The detector automatically selects the default model based on your hardware:
# - For Hailo-8 hardware: YOLOv6n (default: yolov6n.hef) # - For Hailo-8 hardware: YOLOv6n (default: yolov6n.hef)
# - For Hailo-8L hardware: YOLOv6n (default: yolov6n.hef) # - For Hailo-8L hardware: YOLOv6n (default: yolov6n.hef)
# #
# Optionally, you can specify a local model path to override the default. # Optionally, you can specify a local model path to override the default.
# If a local path is provided and the file exists, it will be used instead of downloading. # If a local path is provided and the file exists, it will be used instead of downloading.
# Example: # Example:
# path: /config/model_cache/hailo/yolov6n.hef # path: /config/model_cache/hailo/yolov6n.hef
# #
# You can also override using a custom URL: # You can also override using a custom URL:
# path: https://hailo-model-zoo.s3.eu-west-2.amazonaws.com/ModelZoo/Compiled/v2.14.0/hailo8/yolov6n.hef # path: https://hailo-model-zoo.s3.eu-west-2.amazonaws.com/ModelZoo/Compiled/v2.14.0/hailo8/yolov6n.hef
# just make sure to give it the write configuration based on the model # just make sure to give it the write configuration based on the model
- key: ssd - key: ssd
label: SSD MobileNet v1 label: SSD MobileNet v1
recommended: false recommended: false
@@ -111,18 +113,19 @@ hailo8l:
type: hailo8l type: hailo8l
device: PCIe device: PCIe
model: models:
width: 300 default:
height: 300 width: 300
input_tensor: nhwc height: 300
input_pixel_format: rgb input_tensor: nhwc
model_type: ssd input_pixel_format: rgb
# Specify the local model path (if available) or URL for SSD MobileNet v1. model_type: ssd
# Example with a local path: # Specify the local model path (if available) or URL for SSD MobileNet v1.
# path: /config/model_cache/h8l_cache/ssd_mobilenet_v1.hef # Example with a local path:
# # path: /config/model_cache/h8l_cache/ssd_mobilenet_v1.hef
# Or override using a custom URL: #
# path: https://hailo-model-zoo.s3.eu-west-2.amazonaws.com/ModelZoo/Compiled/v2.14.0/hailo8l/ssd_mobilenet_v1.hef # Or override using a custom URL:
# path: https://hailo-model-zoo.s3.eu-west-2.amazonaws.com/ModelZoo/Compiled/v2.14.0/hailo8l/ssd_mobilenet_v1.hef
openvino: openvino:
title: OpenVINO title: OpenVINO
models: models:
@@ -171,14 +174,15 @@ openvino:
type: openvino type: openvino
device: GPU # or NPU device: GPU # or NPU
model: models:
model_type: yolo-generic default:
width: 320 # <--- should match the imgsize set during model export model_type: yolo-generic
height: 320 # <--- should match the imgsize set during model export width: 320 # <--- should match the imgsize set during model export
input_tensor: nchw height: 320 # <--- should match the imgsize set during model export
input_dtype: float input_tensor: nchw
path: /config/model_cache/yolo.onnx # use the filename you generated above input_dtype: float
labelmap_path: /labelmap/coco-80.txt path: /config/model_cache/yolo.onnx # use the filename you generated above
labelmap_path: /labelmap/coco-80.txt
- key: ssd - key: ssd
label: SSDLite MobileNet v2 label: SSDLite MobileNet v2
recommended: false recommended: false
@@ -202,13 +206,14 @@ openvino:
type: openvino type: openvino
device: GPU # Or NPU device: GPU # Or NPU
model: models:
width: 300 default:
height: 300 width: 300
input_tensor: nhwc height: 300
input_pixel_format: bgr input_tensor: nhwc
path: /openvino-model/ssdlite_mobilenet_v2.xml input_pixel_format: bgr
labelmap_path: /openvino-model/coco_91cl_bkgr.txt path: /openvino-model/ssdlite_mobilenet_v2.xml
labelmap_path: /openvino-model/coco_91cl_bkgr.txt
- key: yolo-legacy - key: yolo-legacy
label: YOLO (v3, v4, v7) label: YOLO (v3, v4, v7)
recommended: false recommended: false
@@ -240,14 +245,15 @@ openvino:
type: openvino type: openvino
device: GPU # or NPU device: GPU # or NPU
model: models:
model_type: yolo-generic default:
width: 320 # <--- should match the imgsize set during model export model_type: yolo-generic
height: 320 # <--- should match the imgsize set during model export width: 320 # <--- should match the imgsize set during model export
input_tensor: nchw height: 320 # <--- should match the imgsize set during model export
input_dtype: float input_tensor: nchw
path: /config/model_cache/yolo.onnx # use the filename you generated above input_dtype: float
labelmap_path: /labelmap/coco-80.txt path: /config/model_cache/yolo.onnx # use the filename you generated above
labelmap_path: /labelmap/coco-80.txt
- key: yolonas - key: yolonas
label: YOLO-NAS label: YOLO-NAS
recommended: false recommended: false
@@ -280,14 +286,15 @@ openvino:
type: openvino type: openvino
device: GPU device: GPU
model: models:
model_type: yolonas default:
width: 320 # <--- should match whatever was set in notebook model_type: yolonas
height: 320 # <--- should match whatever was set in notebook width: 320 # <--- should match whatever was set in notebook
input_tensor: nchw height: 320 # <--- should match whatever was set in notebook
input_pixel_format: bgr input_tensor: nchw
path: /config/yolo_nas_s.onnx input_pixel_format: bgr
labelmap_path: /labelmap/coco-80.txt path: /config/yolo_nas_s.onnx
labelmap_path: /labelmap/coco-80.txt
- key: yolox - key: yolox
label: YOLOX label: YOLOX
recommended: false recommended: false
@@ -308,10 +315,11 @@ openvino:
type: openvino type: openvino
device: GPU device: GPU
model: models:
model_type: yolox default:
path: /config/model_cache/yolox.onnx # use the filename you generated above model_type: yolox
labelmap_path: /labelmap/coco-80.txt path: /config/model_cache/yolox.onnx # use the filename you generated above
labelmap_path: /labelmap/coco-80.txt
- key: rfdetr - key: rfdetr
label: RF-DETR label: RF-DETR
recommended: false recommended: false
@@ -350,13 +358,14 @@ openvino:
type: openvino type: openvino
device: GPU device: GPU
model: models:
model_type: rfdetr default:
width: 320 model_type: rfdetr
height: 320 width: 320
input_tensor: nchw height: 320
input_dtype: float input_tensor: nchw
path: /config/model_cache/rfdetr.onnx # use the filename you generated above input_dtype: float
path: /config/model_cache/rfdetr.onnx # use the filename you generated above
- key: dfine - key: dfine
label: D-FINE / DEIMv2 label: D-FINE / DEIMv2
recommended: false recommended: false
@@ -448,14 +457,15 @@ openvino:
type: openvino type: openvino
device: CPU device: CPU
model: models:
model_type: dfine default:
width: 640 model_type: dfine
height: 640 width: 640
input_tensor: nchw height: 640
input_dtype: float input_tensor: nchw
path: /config/model_cache/dfine-s.onnx # use the filename you generated above input_dtype: float
labelmap_path: /labelmap/coco-80.txt path: /config/model_cache/dfine-s.onnx # use the filename you generated above
labelmap_path: /labelmap/coco-80.txt
appleSilicon: appleSilicon:
title: Apple Silicon title: Apple Silicon
models: models:
@@ -504,14 +514,15 @@ appleSilicon:
type: zmq type: zmq
endpoint: tcp://host.docker.internal:5555 endpoint: tcp://host.docker.internal:5555
model: models:
model_type: yolo-generic default:
width: 320 # <--- should match the imgsize set during model export model_type: yolo-generic
height: 320 # <--- should match the imgsize set during model export width: 320 # <--- should match the imgsize set during model export
input_tensor: nchw height: 320 # <--- should match the imgsize set during model export
input_dtype: float input_tensor: nchw
path: /config/model_cache/yolo.onnx # use the filename you generated above input_dtype: float
labelmap_path: /labelmap/coco-80.txt path: /config/model_cache/yolo.onnx # use the filename you generated above
labelmap_path: /labelmap/coco-80.txt
- key: yolo-legacy - key: yolo-legacy
label: YOLO (v3, v4, v7) label: YOLO (v3, v4, v7)
recommended: false recommended: false
@@ -543,14 +554,15 @@ appleSilicon:
type: zmq type: zmq
endpoint: tcp://host.docker.internal:5555 endpoint: tcp://host.docker.internal:5555
model: models:
model_type: yolo-generic default:
width: 320 # <--- should match the imgsize set during model export model_type: yolo-generic
height: 320 # <--- should match the imgsize set during model export width: 320 # <--- should match the imgsize set during model export
input_tensor: nchw height: 320 # <--- should match the imgsize set during model export
input_dtype: float input_tensor: nchw
path: /config/model_cache/yolo.onnx # use the filename you generated above input_dtype: float
labelmap_path: /labelmap/coco-80.txt path: /config/model_cache/yolo.onnx # use the filename you generated above
labelmap_path: /labelmap/coco-80.txt
onnx: onnx:
title: ONNX title: ONNX
models: models:
@@ -598,14 +610,15 @@ onnx:
onnx: onnx:
type: onnx type: onnx
model: models:
model_type: yolo-generic default:
width: 320 # <--- should match the imgsize set during model export model_type: yolo-generic
height: 320 # <--- should match the imgsize set during model export width: 320 # <--- should match the imgsize set during model export
input_tensor: nchw height: 320 # <--- should match the imgsize set during model export
input_dtype: float input_tensor: nchw
path: /config/model_cache/yolo.onnx # use the filename you generated above input_dtype: float
labelmap_path: /labelmap/coco-80.txt path: /config/model_cache/yolo.onnx # use the filename you generated above
labelmap_path: /labelmap/coco-80.txt
- key: rfdetr - key: rfdetr
label: RF-DETR label: RF-DETR
recommended: false recommended: false
@@ -643,13 +656,14 @@ onnx:
onnx: onnx:
type: onnx type: onnx
model: models:
model_type: rfdetr default:
width: 320 model_type: rfdetr
height: 320 width: 320
input_tensor: nchw height: 320
input_dtype: float input_tensor: nchw
path: /config/model_cache/rfdetr.onnx # use the filename you generated above input_dtype: float
path: /config/model_cache/rfdetr.onnx # use the filename you generated above
- key: yolonas - key: yolonas
label: YOLO-NAS label: YOLO-NAS
recommended: false recommended: false
@@ -681,14 +695,15 @@ onnx:
onnx: onnx:
type: onnx type: onnx
model: models:
model_type: yolonas default:
width: 320 # <--- should match whatever was set in notebook model_type: yolonas
height: 320 # <--- should match whatever was set in notebook width: 320 # <--- should match whatever was set in notebook
input_pixel_format: bgr height: 320 # <--- should match whatever was set in notebook
input_tensor: nchw input_pixel_format: bgr
path: /config/yolo_nas_s.onnx input_tensor: nchw
labelmap_path: /labelmap/coco-80.txt path: /config/yolo_nas_s.onnx
labelmap_path: /labelmap/coco-80.txt
- key: yolox - key: yolox
label: YOLOX label: YOLOX
recommended: false recommended: false
@@ -711,14 +726,15 @@ onnx:
onnx: onnx:
type: onnx type: onnx
model: models:
model_type: yolox default:
width: 416 # <--- should match the imgsize set during model export model_type: yolox
height: 416 # <--- should match the imgsize set during model export width: 416 # <--- should match the imgsize set during model export
input_tensor: nchw height: 416 # <--- should match the imgsize set during model export
input_dtype: float_denorm input_tensor: nchw
path: /config/model_cache/yolox_tiny.onnx # use the filename you generated above input_dtype: float_denorm
labelmap_path: /labelmap/coco-80.txt path: /config/model_cache/yolox_tiny.onnx # use the filename you generated above
labelmap_path: /labelmap/coco-80.txt
- key: dfine - key: dfine
label: D-FINE / DEIMv2 label: D-FINE / DEIMv2
recommended: false recommended: false
@@ -809,14 +825,15 @@ onnx:
onnx: onnx:
type: onnx type: onnx
model: models:
model_type: dfine default:
width: 640 model_type: dfine
height: 640 width: 640
input_tensor: nchw height: 640
input_dtype: float input_tensor: nchw
path: /config/model_cache/dfine_m_obj2coco.onnx # use the filename you generated above input_dtype: float
labelmap_path: /labelmap/coco-80.txt path: /config/model_cache/dfine_m_obj2coco.onnx # use the filename you generated above
labelmap_path: /labelmap/coco-80.txt
- key: yolo-legacy - key: yolo-legacy
label: YOLO (v3, v4, v7) label: YOLO (v3, v4, v7)
recommended: false recommended: false
@@ -847,14 +864,15 @@ onnx:
onnx: onnx:
type: onnx type: onnx
model: models:
model_type: yolo-generic default:
width: 320 # <--- should match the imgsize set during model export model_type: yolo-generic
height: 320 # <--- should match the imgsize set during model export width: 320 # <--- should match the imgsize set during model export
input_tensor: nchw height: 320 # <--- should match the imgsize set during model export
input_dtype: float input_tensor: nchw
path: /config/model_cache/yolo.onnx # use the filename you generated above input_dtype: float
labelmap_path: /labelmap/coco-80.txt path: /config/model_cache/yolo.onnx # use the filename you generated above
labelmap_path: /labelmap/coco-80.txt
cpu: cpu:
title: CPU title: CPU
models: models:
@@ -928,18 +946,19 @@ memryx:
type: memryx type: memryx
device: PCIe:0 device: PCIe:0
model: models:
model_type: yolonas default:
width: 320 # (Can be set to 640 for higher resolution) model_type: yolonas
height: 320 # (Can be set to 640 for higher resolution) width: 320 # (Can be set to 640 for higher resolution)
input_tensor: nchw height: 320 # (Can be set to 640 for higher resolution)
input_dtype: float input_tensor: nchw
labelmap_path: /labelmap/coco-80.txt input_dtype: float
# Optional: The model is normally fetched through the runtime, so 'path' can be omitted unless you want to use a custom or local model. labelmap_path: /labelmap/coco-80.txt
# path: /config/yolonas.zip # Optional: The model is normally fetched through the runtime, so 'path' can be omitted unless you want to use a custom or local model.
# The .zip file must contain: # path: /config/yolonas.zip
# ├── yolonas.dfp (a file ending with .dfp) # The .zip file must contain:
# ── yolonas_post.onnx (optional; only if the model includes a cropped post-processing network) # ── yolonas.dfp (a file ending with .dfp)
# └── yolonas_post.onnx (optional; only if the model includes a cropped post-processing network)
- key: yolov9 - key: yolov9
label: YOLOv9 label: YOLOv9
recommended: false recommended: false
@@ -965,17 +984,18 @@ memryx:
type: memryx type: memryx
device: PCIe:0 device: PCIe:0
model: models:
model_type: yolo-generic default:
width: 320 # (Can be set to 640 for higher resolution) model_type: yolo-generic
height: 320 # (Can be set to 640 for higher resolution) width: 320 # (Can be set to 640 for higher resolution)
input_tensor: nchw height: 320 # (Can be set to 640 for higher resolution)
input_dtype: float input_tensor: nchw
labelmap_path: /labelmap/coco-80.txt input_dtype: float
# Optional: The model is normally fetched through the runtime, so 'path' can be omitted unless you want to use a custom or local model. labelmap_path: /labelmap/coco-80.txt
# path: /config/yolov9.zip # Optional: The model is normally fetched through the runtime, so 'path' can be omitted unless you want to use a custom or local model.
# The .zip file must contain: # path: /config/yolov9.zip
# ├── yolov9.dfp (a file ending with .dfp) # The .zip file must contain:
# ├── yolov9.dfp (a file ending with .dfp)
- key: yolox - key: yolox
label: YOLOX label: YOLOX
recommended: false recommended: false
@@ -1001,17 +1021,18 @@ memryx:
type: memryx type: memryx
device: PCIe:0 device: PCIe:0
model: models:
model_type: yolox default:
width: 640 model_type: yolox
height: 640 width: 640
input_tensor: nchw height: 640
input_dtype: float_denorm input_tensor: nchw
labelmap_path: /labelmap/coco-80.txt input_dtype: float_denorm
# Optional: The model is normally fetched through the runtime, so 'path' can be omitted unless you want to use a custom or local model. labelmap_path: /labelmap/coco-80.txt
# path: /config/yolox.zip # Optional: The model is normally fetched through the runtime, so 'path' can be omitted unless you want to use a custom or local model.
# The .zip file must contain: # path: /config/yolox.zip
# ├── yolox.dfp (a file ending with .dfp) # The .zip file must contain:
# ├── yolox.dfp (a file ending with .dfp)
- key: ssd - key: ssd
label: SSDLite MobileNet v2 label: SSDLite MobileNet v2
recommended: false recommended: false
@@ -1037,18 +1058,19 @@ memryx:
type: memryx type: memryx
device: PCIe:0 device: PCIe:0
model: models:
model_type: ssd default:
width: 320 model_type: ssd
height: 320 width: 320
input_tensor: nchw height: 320
input_dtype: float input_tensor: nchw
labelmap_path: /labelmap/coco-80.txt input_dtype: float
# Optional: The model is normally fetched through the runtime, so 'path' can be omitted unless you want to use a custom or local model. labelmap_path: /labelmap/coco-80.txt
# path: /config/ssdlite_mobilenet.zip # Optional: The model is normally fetched through the runtime, so 'path' can be omitted unless you want to use a custom or local model.
# The .zip file must contain: # path: /config/ssdlite_mobilenet.zip
# ├── ssdlite_mobilenet.dfp (a file ending with .dfp) # The .zip file must contain:
# ── ssdlite_mobilenet_post.onnx (optional; only if the model includes a cropped post-processing network) # ── ssdlite_mobilenet.dfp (a file ending with .dfp)
# └── ssdlite_mobilenet_post.onnx (optional; only if the model includes a cropped post-processing network)
tensorrt: tensorrt:
title: TensorRT title: TensorRT
models: models:
@@ -1087,13 +1109,14 @@ tensorrt:
type: tensorrt type: tensorrt
device: 0 #This is the default, select the first GPU device: 0 #This is the default, select the first GPU
model: models:
path: /config/model_cache/tensorrt/yolov7-320.trt # use the filename you generated above default:
labelmap_path: /labelmap/coco-80.txt path: /config/model_cache/tensorrt/yolov7-320.trt # use the filename you generated above
input_tensor: nchw labelmap_path: /labelmap/coco-80.txt
input_pixel_format: rgb input_tensor: nchw
width: 320 # MUST match the chosen model i.e yolov7-320 -> 320, yolov4-416 -> 416 input_pixel_format: rgb
height: 320 # MUST match the chosen model i.e yolov7-320 -> 320 yolov4-416 -> 416 width: 320 # MUST match the chosen model i.e yolov7-320 -> 320, yolov4-416 -> 416
height: 320 # MUST match the chosen model i.e yolov7-320 -> 320 yolov4-416 -> 416
synaptics: synaptics:
title: Synaptics title: Synaptics
models: models:
@@ -1261,14 +1284,15 @@ axengine:
axengine: axengine:
type: axengine type: axengine
model: models:
path: frigate-yolov9-tiny default:
model_type: yolo-generic path: frigate-yolov9-tiny
width: 320 model_type: yolo-generic
height: 320 width: 320
input_dtype: int height: 320
input_pixel_format: bgr input_dtype: int
labelmap_path: /labelmap/coco-80.txt input_pixel_format: bgr
labelmap_path: /labelmap/coco-80.txt
degirumAiServer: degirumAiServer:
title: DeGirum AI Server title: DeGirum AI Server
models: models:
+46 -36
View File
@@ -157,44 +157,51 @@ auth:
- front_door - front_door
- back_yard - back_yard
# Optional: model modifications # Optional: named object detection models (default: a single model named "default")
# Each entry defines a model; cameras choose which model to use with detect.model.
# Detectors that support multiple models (openvino, onnx, tensorrt, cpu, rknn) run
# one instance per model in use. Detectors that only support a single model
# (edgetpu, hailo8l, memryx, and others) are assigned to models round robin, so at
# least as many of those detectors as models are required when no multi-model
# capable detector is configured.
# NOTE: The default values are for the EdgeTPU detector. # NOTE: The default values are for the EdgeTPU detector.
# Other detectors will require the model config to be set. # Other detectors will require the model config to be set.
model: models:
# Required: path to the model. Frigate+ models use plus://<model_id> (default: automatic based on detector) default:
path: /edgetpu_model.tflite # Required: path to the model. Frigate+ models use plus://<model_id> (default: automatic based on detector)
# Required: path to the labelmap (default: shown below) path: /edgetpu_model.tflite
labelmap_path: /labelmap.txt # Required: path to the labelmap (default: shown below)
# Required: Object detection model input width (default: shown below) labelmap_path: /labelmap.txt
width: 320 # Required: Object detection model input width (default: shown below)
# Required: Object detection model input height (default: shown below) width: 320
height: 320 # Required: Object detection model input height (default: shown below)
# Required: Object detection model input colorspace height: 320
# Valid values are rgb, bgr, or yuv. (default: shown below) # Required: Object detection model input colorspace
input_pixel_format: rgb # Valid values are rgb, bgr, or yuv. (default: shown below)
# Required: Object detection model input tensor format input_pixel_format: rgb
# Valid values are nhwc, nchw, hwnc, or hwcn (default: shown below) # Required: Object detection model input tensor format
input_tensor: nhwc # Valid values are nhwc, nchw, hwnc, or hwcn (default: shown below)
# Optional: Data type of the model input tensor input_tensor: nhwc
# Valid values are float, float_denorm, or int (default: shown below) # Optional: Data type of the model input tensor
input_dtype: int # Valid values are float, float_denorm, or int (default: shown below)
# Required: Object detection model architecture, used by detectors that support more input_dtype: int
# than one model type (openvino, onnx, rknn, memryx, axengine, synaptics, and others) # Required: Object detection model architecture, used by detectors that support more
# Valid values are ssd, yolox, yolonas, yolo-generic, rfdetr, dfine (default: shown below) # than one model type (openvino, onnx, rknn, memryx, axengine, synaptics, and others)
model_type: ssd # Valid values are ssd, yolox, yolonas, yolo-generic, rfdetr, dfine (default: shown below)
# Required: Label name modifications. These are merged into the standard labelmap. model_type: ssd
labelmap: # Required: Label name modifications. These are merged into the standard labelmap.
2: vehicle labelmap:
# Optional: Map of object labels to their attribute labels (default: depends on model) 2: vehicle
attributes_map: # Optional: Map of object labels to their attribute labels (default: depends on model)
person: attributes_map:
- amazon person:
- face - amazon
car: - face
- amazon car:
- fedex - amazon
- license_plate - fedex
- ups - license_plate
- ups
# Optional: Audio Events Configuration # Optional: Audio Events Configuration
# NOTE: Can be overridden at the camera level # NOTE: Can be overridden at the camera level
@@ -302,6 +309,9 @@ ffmpeg:
detect: detect:
# Optional: enables detection for the camera (default: shown below) # Optional: enables detection for the camera (default: shown below)
enabled: False enabled: False
# Optional: name of the model (key under models) used by this camera
# (default: the only defined model, or the model named "default")
model: default
# Optional: width of the frame for the input with the detect role (default: use native stream resolution) # Optional: width of the frame for the input with the detect role (default: use native stream resolution)
width: 1280 width: 1280
# Optional: height of the frame for the input with the detect role (default: use native stream resolution) # Optional: height of the frame for the input with the detect role (default: use native stream resolution)
+17 -15
View File
@@ -192,12 +192,13 @@ Navigate to <NavPath path="Settings > System > Detectors and model" /> and open
```yaml ```yaml
# Optional: model config # Optional: model config
model: models:
path: /path/to/model default:
width: 320 path: /path/to/model
height: 320 width: 320
input_tensor: "nhwc" height: 320
input_pixel_format: "bgr" input_tensor: "nhwc"
input_pixel_format: "bgr"
``` ```
</TabItem> </TabItem>
@@ -214,15 +215,16 @@ If the labelmap is customized then the labels used for alerts will need to be ad
The labelmap can be customized to your needs. A common reason to do this is to combine multiple object types that are easily confused when you don't need to be as granular such as car/truck. By default, truck is renamed to car because they are often confused. You cannot add new object types, but you can change the names of existing objects in the model. The labelmap can be customized to your needs. A common reason to do this is to combine multiple object types that are easily confused when you don't need to be as granular such as car/truck. By default, truck is renamed to car because they are often confused. You cannot add new object types, but you can change the names of existing objects in the model.
```yaml ```yaml
model: models:
labelmap: default:
2: vehicle labelmap:
3: vehicle 2: vehicle
5: vehicle 3: vehicle
7: vehicle 5: vehicle
15: animal 7: vehicle
16: animal 15: animal
17: animal 16: animal
17: animal
``` ```
Note that if you rename objects in the labelmap, you will also need to update your `objects -> track` list as well. Note that if you rename objects in the labelmap, you will also need to update your `objects -> track` list as well.
+8 -7
View File
@@ -334,13 +334,14 @@ detectors:
type: openvino type: openvino
device: AUTO device: AUTO
model: models:
width: 300 default:
height: 300 width: 300
input_tensor: nhwc height: 300
input_pixel_format: bgr input_tensor: nhwc
path: /openvino-model/ssdlite_mobilenet_v2.xml input_pixel_format: bgr
labelmap_path: /openvino-model/coco_91cl_bkgr.txt path: /openvino-model/ssdlite_mobilenet_v2.xml
labelmap_path: /openvino-model/coco_91cl_bkgr.txt
record: record:
enabled: True enabled: True
+53 -15
View File
@@ -91,6 +91,41 @@ The best detection accuracy comes from a model trained on images that look like
::: :::
### Running multiple models
Models are defined as named entries under `models`, and each camera selects the model it uses with `detect.model`. This makes it possible to run different models for different groups of cameras, for example a dedicated model for indoor cameras, outdoor cameras, or thermal cameras.
```yaml
detectors:
ov:
type: openvino
device: GPU
models:
indoor:
path: /config/model_cache/indoor-model.xml
model_type: yolo-generic
width: 320
height: 320
outdoor:
path: plus://<your_model_id>
cameras:
living_room:
detect:
model: indoor
driveway:
detect:
model: outdoor
```
When only one model is defined, all cameras use it automatically. With multiple models, cameras use the model named `default` unless `detect.model` selects another one; `detect.model` can also be set globally and overridden per camera.
How detectors handle multiple models depends on the hardware:
- **Detectors that support multiple models** (`openvino`, `onnx`, `tensorrt`, `cpu`, `rknn`): a single detector entry is automatically expanded into one instance per model in use. For example, detector `ov` with models `indoor` and `outdoor` runs as `ov_indoor` and `ov_outdoor`, and each instance appears separately in the System Metrics page. Keep in mind that each instance loads its own copy of the model, which increases GPU memory usage.
- **Detectors that only support a single model** (`edgetpu`, `hailo8l`, `memryx`, and other single-session hardware): each detector entry serves exactly one model. Detector entries are assigned to models round robin, so running two models on Coral hardware requires two Corals. If these are the only detectors configured and there are fewer of them than models in use, Frigate will fail to start with an error explaining the options.
# Officially Supported Detectors # Officially Supported Detectors
Frigate provides a number of builtin detector types. By default, Frigate will use a single CPU detector. Other detectors may require additional configuration as described below. When using multiple detectors they will run in dedicated processes, but pull from a common queue of detection requests from across all cameras. Frigate provides a number of builtin detector types. By default, Frigate will use a single CPU detector. Other detectors may require additional configuration as described below. When using multiple detectors they will run in dedicated processes, but pull from a common queue of detection requests from across all cameras.
@@ -789,11 +824,12 @@ You can set it to:
- A path to some model.json. - A path to some model.json.
```yaml ```yaml
model: models:
path: ./mobilenet_v2_ssd_coco--300x300_quant_n2x_orca1_1 # directory to model .json and file default:
width: 300 # width is in the model name as the first number in the "int"x"int" section path: ./mobilenet_v2_ssd_coco--300x300_quant_n2x_orca1_1 # directory to model .json and file
height: 300 # height is in the model name as the second number in the "int"x"int" section width: 300 # width is in the model name as the first number in the "int"x"int" section
input_pixel_format: rgb/bgr # look at the model.json to figure out which to put here height: 300 # height is in the model name as the second number in the "int"x"int" section
input_pixel_format: rgb/bgr # look at the model.json to figure out which to put here
``` ```
#### Local Inference #### Local Inference
@@ -809,11 +845,12 @@ It is also possible to eliminate the need for an AI server and run the hardware
Once `degirum_detector` is setup, you can choose a model through 'model' section in the `config.yml` file. Once `degirum_detector` is setup, you can choose a model through 'model' section in the `config.yml` file.
```yaml ```yaml
model: models:
path: mobilenet_v2_ssd_coco--300x300_quant_n2x_orca1_1 default:
width: 300 # width is in the model name as the first number in the "int"x"int" section path: mobilenet_v2_ssd_coco--300x300_quant_n2x_orca1_1
height: 300 # height is in the model name as the second number in the "int"x"int" section width: 300 # width is in the model name as the first number in the "int"x"int" section
input_pixel_format: rgb/bgr # look at the model.json to figure out which to put here height: 300 # height is in the model name as the second number in the "int"x"int" section
input_pixel_format: rgb/bgr # look at the model.json to figure out which to put here
``` ```
#### AI Hub Cloud Inference #### AI Hub Cloud Inference
@@ -829,11 +866,12 @@ If you do not possess whatever hardware you want to run, there's also the option
Once `degirum_detector` is setup, you can choose a model through 'model' section in the `config.yml` file. Once `degirum_detector` is setup, you can choose a model through 'model' section in the `config.yml` file.
```yaml ```yaml
model: models:
path: mobilenet_v2_ssd_coco--300x300_quant_n2x_orca1_1 default:
width: 300 # width is in the model name as the first number in the "int"x"int" section path: mobilenet_v2_ssd_coco--300x300_quant_n2x_orca1_1
height: 300 # height is in the model name as the second number in the "int"x"int" section width: 300 # width is in the model name as the first number in the "int"x"int" section
input_pixel_format: rgb/bgr # look at the model.json to figure out which to put here height: 300 # height is in the model name as the second number in the "int"x"int" section
input_pixel_format: rgb/bgr # look at the model.json to figure out which to put here
``` ```
## AXERA ## AXERA
+8 -7
View File
@@ -228,13 +228,14 @@ detectors: # <---- add detectors
device: GPU device: GPU
# We will use the default MobileNet_v2 model from OpenVINO. # We will use the default MobileNet_v2 model from OpenVINO.
model: models:
width: 300 default:
height: 300 width: 300
input_tensor: nhwc height: 300
input_pixel_format: bgr input_tensor: nhwc
path: /openvino-model/ssdlite_mobilenet_v2.xml input_pixel_format: bgr
labelmap_path: /openvino-model/coco_91cl_bkgr.txt path: /openvino-model/ssdlite_mobilenet_v2.xml
labelmap_path: /openvino-model/coco_91cl_bkgr.txt
cameras: cameras:
name_of_your_camera: name_of_your_camera:
+10 -8
View File
@@ -64,8 +64,9 @@ You can either choose the new model from the <NavPath path="Settings > System >
```yaml ```yaml
detectors: ... detectors: ...
model: models:
path: plus://<your_model_id> default:
path: plus://<your_model_id>
``` ```
:::note :::note
@@ -79,10 +80,11 @@ Models are downloaded into the `/config/model_cache` folder and only downloaded
If needed, you can override the labelmap for Frigate+ models. This is not recommended as renaming labels will break the Submit to Frigate+ feature if the labels are not available in Frigate+. If needed, you can override the labelmap for Frigate+ models. This is not recommended as renaming labels will break the Submit to Frigate+ feature if the labels are not available in Frigate+.
```yaml ```yaml
model: models:
path: plus://<your_model_id> default:
labelmap: path: plus://<your_model_id>
3: animal labelmap:
4: animal 3: animal
5: animal 4: animal
5: animal
``` ```
+3 -2
View File
@@ -38,8 +38,9 @@ Navigate to <NavPath path="Settings > System > Detectors and model" />. In the *
```yaml ```yaml
detectors: ... detectors: ...
model: models:
path: plus://<your_model_id> default:
path: plus://<your_model_id>
``` ```
:::tip :::tip
+37 -25
View File
@@ -372,31 +372,40 @@ def config(request: Request):
config["go2rtc"]["streams"][stream_name] = cleaned config["go2rtc"]["streams"][stream_name] = cleaned
config["plus"] = {"enabled": request.app.frigate_config.plus_api.is_active()} config["plus"] = {"enabled": request.app.frigate_config.plus_api.is_active()}
config["model"]["colormap"] = config_obj.model.colormap
config["model"]["all_attributes"] = config_obj.model.all_attributes
config["model"]["non_logo_attributes"] = config_obj.model.non_logo_attributes
# Add model plus data if plus is enabled for model_key, model in config_obj.models.items():
if config["plus"]["enabled"]: model_dict = config["models"][model_key]
model_path = config.get("model", {}).get("path") model_dict["colormap"] = model.colormap
if model_path: model_dict["all_attributes"] = model.all_attributes
model_json_path = FilePath(model_path).with_suffix(".json") model_dict["non_logo_attributes"] = model.non_logo_attributes
try:
with open(model_json_path) as f:
model_plus_data = json.load(f)
config["model"]["plus"] = model_plus_data
except FileNotFoundError:
config["model"]["plus"] = None
except json.JSONDecodeError:
config["model"]["plus"] = None
else:
config["model"]["plus"] = None
# use merged labelamp # Add model plus data if plus is enabled
for detector_config in config["detectors"].values(): if config["plus"]["enabled"]:
detector_config["model"]["labelmap"] = ( model_plus_data = None
request.app.frigate_config.model.merged_labelmap
) if model.path:
model_json_path = FilePath(model.path).with_suffix(".json")
try:
with open(model_json_path) as f:
model_plus_data = json.load(f)
except (FileNotFoundError, json.JSONDecodeError):
model_plus_data = None
model_dict["plus"] = model_plus_data
# legacy single-model block kept for frontend compatibility, remove
# once the UI is fully multi-model aware
default_model_key = (
"default" if "default" in config_obj.models else next(iter(config_obj.models))
)
config["model"] = config["models"][default_model_key]
# use each detector's assigned merged labelmap
for key, detector_config in config["detectors"].items():
if config_obj.detectors[key].model:
detector_config["model"]["labelmap"] = config_obj.detectors[
key
].model.merged_labelmap
return JSONResponse(content=config) return JSONResponse(content=config)
@@ -1323,8 +1332,11 @@ def plusModels(request: Request, filterByCurrentModelDetector: bool = False):
modelList = models["list"] modelList = models["list"]
# current model type # current model type, based on the default model until the UI is
modelType = request.app.frigate_config.model.model_type # fully multi-model aware
config_models = request.app.frigate_config.models
default_model = config_models.get("default") or next(iter(config_models.values()))
modelType = default_model.model_type
# current detectorType for comparing to supportedDetectors # current detectorType for comparing to supportedDetectors
detectorType = list(request.app.frigate_config.detectors.values())[0].type detectorType = list(request.app.frigate_config.detectors.values())[0].type
+1 -1
View File
@@ -813,7 +813,7 @@ async def event_snapshot(
timestamp_style=request.app.frigate_config.cameras[ timestamp_style=request.app.frigate_config.cameras[
event.camera event.camera
].timestamp_style, ].timestamp_style,
colormap=request.app.frigate_config.model.colormap, colormap=request.app.frigate_config.model_for_camera(event.camera).colormap,
) )
except DoesNotExist: except DoesNotExist:
# see if the object is currently being tracked # see if the object is currently being tracked
+19 -17
View File
@@ -97,7 +97,9 @@ class FrigateApp:
self.metrics_manager = manager self.metrics_manager = manager
self.audio_process: mp.Process | None = None self.audio_process: mp.Process | None = None
self.stop_event = stop_event self.stop_event = stop_event
self.detection_queue: Queue = mp.Queue() self.detection_queues: dict[str, Queue] = {
model_key: mp.Queue() for model_key in config.models
}
self.detectors: dict[str, ObjectDetectProcess] = {} self.detectors: dict[str, ObjectDetectProcess] = {}
self.detection_shms: list[mp.shared_memory.SharedMemory] = [] self.detection_shms: list[mp.shared_memory.SharedMemory] = []
self.log_queue: Queue = mp.Queue() self.log_queue: Queue = mp.Queue()
@@ -363,20 +365,14 @@ class FrigateApp:
) )
def start_detectors(self) -> None: def start_detectors(self) -> None:
for name in self.config.cameras.keys(): for name, camera_config in self.config.cameras.items():
camera_model = self.config.models[camera_config.detect.model]
try: try:
largest_frame = max(
[
det.model.height * det.model.width * 3
if det.model is not None
else 320
for det in self.config.detectors.values()
]
)
shm_in = UntrackedSharedMemory( shm_in = UntrackedSharedMemory(
name=name, name=name,
create=True, create=True,
size=largest_frame, size=camera_model.height * camera_model.width * 3,
) )
except FileExistsError: except FileExistsError:
shm_in = UntrackedSharedMemory(name=name) shm_in = UntrackedSharedMemory(name=name)
@@ -391,11 +387,16 @@ class FrigateApp:
self.detection_shms.append(shm_in) self.detection_shms.append(shm_in)
self.detection_shms.append(shm_out) self.detection_shms.append(shm_out)
for name, detector_config in self.config.detectors.items(): for name, detector_config in self.config.detector_instances.items():
cameras_using_model = [
camera_name
for camera_name, camera_config in self.config.cameras.items()
if camera_config.detect.model == detector_config.model_key
]
self.detectors[name] = ObjectDetectProcess( self.detectors[name] = ObjectDetectProcess(
name, name,
self.detection_queue, self.detection_queues[detector_config.model_key],
list(self.config.cameras.keys()), cameras_using_model,
self.config, self.config,
detector_config, detector_config,
self.stop_event, self.stop_event,
@@ -430,7 +431,7 @@ class FrigateApp:
def start_camera_processor(self) -> None: def start_camera_processor(self) -> None:
self.camera_maintainer = CameraMaintainer( self.camera_maintainer = CameraMaintainer(
self.config, self.config,
self.detection_queue, self.detection_queues,
self.detected_frames_queue, self.detected_frames_queue,
self.camera_metrics, self.camera_metrics,
self.ptz_metrics, self.ptz_metrics,
@@ -685,8 +686,9 @@ class FrigateApp:
for detector in self.detectors.values(): for detector in self.detectors.values():
detector.stop() detector.stop()
empty_and_close_queue(self.detection_queue) for detection_queue in self.detection_queues.values():
logger.info("Detection queue closed") empty_and_close_queue(detection_queue)
logger.info("Detection queues closed")
self.detected_frames_processor.join() self.detected_frames_processor.join()
empty_and_close_queue(self.detected_frames_queue) empty_and_close_queue(self.detected_frames_queue)
+1 -1
View File
@@ -178,7 +178,7 @@ class CameraActivityManager:
return return
for label in camera_config.objects.track: for label in camera_config.objects.track:
if label in self.config.model.non_logo_attributes: if label in self.config.model_for_camera(camera).non_logo_attributes:
continue continue
new_count = all_objects[label] new_count = all_objects[label]
+11 -16
View File
@@ -29,7 +29,7 @@ class CameraMaintainer(threading.Thread):
def __init__( def __init__(
self, self,
config: FrigateConfig, config: FrigateConfig,
detection_queue: Queue, detection_queues: dict[str, Queue],
detected_frames_queue: Queue, detected_frames_queue: Queue,
camera_metrics: DictProxy, camera_metrics: DictProxy,
ptz_metrics: dict[str, PTZMetrics], ptz_metrics: dict[str, PTZMetrics],
@@ -38,7 +38,7 @@ class CameraMaintainer(threading.Thread):
): ):
super().__init__(name="camera_processor") super().__init__(name="camera_processor")
self.config = config self.config = config
self.detection_queue = detection_queue self.detection_queues = detection_queues
self.detected_frames_queue = detected_frames_queue self.detected_frames_queue = detected_frames_queue
self.stop_event = stop_event self.stop_event = stop_event
self.camera_metrics = camera_metrics self.camera_metrics = camera_metrics
@@ -79,10 +79,11 @@ class CameraMaintainer(threading.Thread):
# create or update region grids for each camera # create or update region grids for each camera
for camera in self.config.cameras.values(): for camera in self.config.cameras.values():
assert camera.name is not None assert camera.name is not None
camera_model = self.config.models[camera.detect.model]
self.region_grids[camera.name] = get_camera_regions_grid( self.region_grids[camera.name] = get_camera_regions_grid(
camera.name, camera.name,
camera.detect, camera.detect,
max(self.config.model.width, self.config.model.height), max(camera_model.width, camera_model.height),
) )
def __calculate_shm_frame_count(self) -> int: def __calculate_shm_frame_count(self) -> int:
@@ -115,6 +116,8 @@ class CameraMaintainer(threading.Thread):
camera_stop_event = self.__ensure_camera_stop_event(name) camera_stop_event = self.__ensure_camera_stop_event(name)
camera_model = self.config.models[config.detect.model]
if runtime: if runtime:
self.camera_metrics[name] = CameraMetrics(self.metrics_manager) self.camera_metrics[name] = CameraMetrics(self.metrics_manager)
self.ptz_metrics[name] = PTZMetrics( self.ptz_metrics[name] = PTZMetrics(
@@ -123,32 +126,24 @@ class CameraMaintainer(threading.Thread):
self.region_grids[name] = get_camera_regions_grid( self.region_grids[name] = get_camera_regions_grid(
name, name,
config.detect, config.detect,
max(self.config.model.width, self.config.model.height), max(camera_model.width, camera_model.height),
) )
try: try:
largest_frame = max(
[
det.model.height * det.model.width * 3
if det.model is not None
else 320
for det in self.config.detectors.values()
]
)
UntrackedSharedMemory(name=f"out-{name}", create=True, size=20 * 6 * 4) UntrackedSharedMemory(name=f"out-{name}", create=True, size=20 * 6 * 4)
UntrackedSharedMemory( UntrackedSharedMemory(
name=name, name=name,
create=True, create=True,
size=largest_frame, size=camera_model.height * camera_model.width * 3,
) )
except FileExistsError: except FileExistsError:
pass pass
camera_process = CameraTracker( camera_process = CameraTracker(
config, config,
self.config.model, camera_model,
self.config.model.merged_labelmap, camera_model.merged_labelmap,
self.detection_queue, self.detection_queues[config.detect.model],
self.detected_frames_queue, self.detected_frames_queue,
self.camera_metrics[name], self.camera_metrics[name],
self.ptz_metrics[name], self.ptz_metrics[name],
+6 -5
View File
@@ -40,6 +40,7 @@ class CameraState:
self.name = name self.name = name
self.config = config self.config = config
self.camera_config = config.cameras[name] self.camera_config = config.cameras[name]
self.model_config = config.model_for_camera(name)
self.frame_manager = frame_manager self.frame_manager = frame_manager
self.best_objects: dict[str, TrackedObject] = {} self.best_objects: dict[str, TrackedObject] = {}
self.tracked_objects: dict[str, TrackedObject] = {} self.tracked_objects: dict[str, TrackedObject] = {}
@@ -101,7 +102,7 @@ class CameraState:
thickness = 1 thickness = 1
else: else:
thickness = 2 thickness = 2
color = self.config.model.colormap.get( color = self.model_config.colormap.get(
obj["label"], (255, 255, 255) obj["label"], (255, 255, 255)
) )
else: else:
@@ -125,7 +126,7 @@ class CameraState:
and obj["frame_time"] == frame_time and obj["frame_time"] == frame_time
): ):
thickness = 5 thickness = 5
color = self.config.model.colormap.get( color = self.model_config.colormap.get(
obj["label"], (255, 255, 255) obj["label"], (255, 255, 255)
) )
@@ -261,7 +262,7 @@ class CameraState:
if draw_options.get("paths"): if draw_options.get("paths"):
for obj in tracked_objects.values(): for obj in tracked_objects.values():
if obj["frame_time"] == frame_time and obj["path_data"]: if obj["frame_time"] == frame_time and obj["path_data"]:
color = self.config.model.colormap.get( color = self.model_config.colormap.get(
obj["label"], (255, 255, 255) obj["label"], (255, 255, 255)
) )
@@ -366,7 +367,7 @@ class CameraState:
for id in new_ids: for id in new_ids:
logger.debug(f"{self.name}: New tracked object ID: {id}") logger.debug(f"{self.name}: New tracked object ID: {id}")
new_obj = tracked_objects[id] = TrackedObject( new_obj = tracked_objects[id] = TrackedObject(
self.config.model, self.model_config,
self.camera_config, self.camera_config,
self.config.ui, self.config.ui,
self.frame_cache, self.frame_cache,
@@ -510,7 +511,7 @@ class CameraState:
sub_label = None sub_label = None
if obj.obj_data.get("sub_label"): if obj.obj_data.get("sub_label"):
if obj.obj_data["sub_label"][0] in self.config.model.all_attributes: if obj.obj_data["sub_label"][0] in self.model_config.all_attributes:
label = obj.obj_data["sub_label"][0] label = obj.obj_data["sub_label"][0]
else: else:
label = f"{object_type}-verified" label = f"{object_type}-verified"
+2 -1
View File
@@ -156,10 +156,11 @@ class Dispatcher:
if camera not in self.config.cameras: if camera not in self.config.cameras:
return None return None
camera_model = self.config.model_for_camera(camera)
grid = get_camera_regions_grid( grid = get_camera_regions_grid(
camera, camera,
self.config.cameras[camera].detect, self.config.cameras[camera].detect,
max(self.config.model.width, self.config.model.height), max(camera_model.width, camera_model.height),
) )
return grid return grid
+5
View File
@@ -50,6 +50,11 @@ class DetectConfig(FrigateBaseModel):
title="Enable object detection", title="Enable object detection",
description="Enable or disable object detection for all cameras; can be overridden per-camera.", description="Enable or disable object detection for all cameras; can be overridden per-camera.",
) )
model: str | None = Field(
default=None,
title="Detection model name",
description="Name of the model (key under `models`) used by this camera. Defaults to the only defined model, or the model named 'default'.",
)
height: int | None = Field( height: int | None = Field(
default=None, default=None,
title="Detect height", title="Detect height",
+154 -32
View File
@@ -4,6 +4,7 @@ import io
import json import json
import logging import logging
import os import os
import re
from typing import Any, Self from typing import Any, Self
import numpy as np import numpy as np
@@ -11,6 +12,7 @@ from pydantic import (
BaseModel, BaseModel,
ConfigDict, ConfigDict,
Field, Field,
PrivateAttr,
TypeAdapter, TypeAdapter,
ValidationInfo, ValidationInfo,
field_validator, field_validator,
@@ -19,7 +21,11 @@ from pydantic import (
from ruamel.yaml import YAML from ruamel.yaml import YAML
from frigate.const import REGEX_JSON from frigate.const import REGEX_JSON
from frigate.detectors import DetectorConfig, ModelConfig from frigate.detectors import (
DetectorConfig,
ModelConfig,
assign_detector_instances,
)
from frigate.detectors.detector_config import BaseDetectorConfig from frigate.detectors.detector_config import BaseDetectorConfig
from frigate.plus import PlusApi from frigate.plus import PlusApi
from frigate.util.builtin import ( from frigate.util.builtin import (
@@ -109,7 +115,7 @@ DEFAULT_CONFIG = f"""
mqtt: mqtt:
enabled: False enabled: False
{_render_default_yaml({"detectors": NEW_CONFIG_DETECTORS, "model": DEFAULT_MODEL})} {_render_default_yaml({"detectors": NEW_CONFIG_DETECTORS, "models": {"default": DEFAULT_MODEL}})}
cameras: {{}} # No cameras defined, UI wizard should be used cameras: {{}} # No cameras defined, UI wizard should be used
version: {CURRENT_CONFIG_VERSION} version: {CURRENT_CONFIG_VERSION}
""" """
@@ -503,10 +509,10 @@ class FrigateConfig(FrigateBaseModel):
title="Detector hardware", title="Detector hardware",
description="Configuration for object detectors (CPU, GPU, ONNX backends) and any detector-specific model settings.", description="Configuration for object detectors (CPU, GPU, ONNX backends) and any detector-specific model settings.",
) )
model: ModelConfig = Field( models: dict[str, ModelConfig] = Field(
default_factory=ModelConfig, default_factory=lambda: {"default": ModelConfig()},
title="Detection model", title="Detection models",
description="Settings to configure a custom object detection model and its input shape.", description="Named object detection models. Cameras select a model with detect.model; detectors are assigned to models automatically.",
) )
# GenAI config (named provider configs: name -> GenAIConfig) # GenAI config (named provider configs: name -> GenAIConfig)
@@ -621,11 +627,37 @@ class FrigateConfig(FrigateBaseModel):
) )
_plus_api: PlusApi _plus_api: PlusApi
_detector_instances: dict[str, BaseDetectorConfig] = PrivateAttr(
default_factory=dict
)
@property @property
def plus_api(self) -> PlusApi: def plus_api(self) -> PlusApi:
return self._plus_api return self._plus_api
@property
def detector_instances(self) -> dict[str, BaseDetectorConfig]:
"""Runtime detector instances expanded per assigned model."""
return self._detector_instances
def model_for_camera(self, camera_name: str) -> ModelConfig:
"""Return the detection model config used by the given camera."""
return self.models[self.cameras[camera_name].detect.model]
@field_validator("models")
@classmethod
def validate_model_names(cls, v: dict[str, ModelConfig]):
if not v:
raise ValueError("At least one model must be defined under models")
for name in v.keys():
if not re.match(r"^[a-zA-Z0-9_-]+$", name):
raise ValueError(
f"Invalid model name '{name}'. Model names can only contain letters, numbers, underscores, and hyphens"
)
return v
@model_validator(mode="after") @model_validator(mode="after")
def post_validation(self, info: ValidationInfo) -> Self: def post_validation(self, info: ValidationInfo) -> Self:
# Load plus api from context, if possible. # Load plus api from context, if possible.
@@ -671,7 +703,12 @@ class FrigateConfig(FrigateBaseModel):
) )
# set default min_score for object attributes # set default min_score for object attributes
for attribute in self.model.all_attributes: all_model_attributes = {
attribute
for model in self.models.values()
for attribute in model.all_attributes
}
for attribute in sorted(all_model_attributes):
existing = self.objects.filters.get(attribute) existing = self.objects.filters.get(attribute)
if existing is None: if existing is None:
self.objects.filters[attribute] = FilterConfig(min_score=0.7) self.objects.filters[attribute] = FilterConfig(min_score=0.7)
@@ -721,8 +758,18 @@ class FrigateConfig(FrigateBaseModel):
exclude_unset=True, exclude_unset=True,
) )
# capture raw model dumps before plus models are loaded so detector
# instances can run their own detector-specific plus validation
raw_model_dumps = {
name: model.model_dump(exclude_unset=True, warnings="none")
for name, model in self.models.items()
}
for model in self.models.values():
model.check_and_load_plus_model(self.plus_api)
adapter = TypeAdapter(DetectorConfig)
for key, detector in self.detectors.items(): for key, detector in self.detectors.items():
adapter = TypeAdapter(DetectorConfig)
model_dict = ( model_dict = (
detector detector
if isinstance(detector, dict) if isinstance(detector, dict)
@@ -737,27 +784,6 @@ class FrigateConfig(FrigateBaseModel):
) )
detector_config.model = None detector_config.model = None
model_config = self.model.model_dump(exclude_unset=True, warnings="none")
if detector_config.model_path:
model_config["path"] = detector_config.model_path
if "path" not in model_config:
if detector_config.type == "cpu" or detector_config.type.endswith(
"_tfl"
):
model_config["path"] = "/cpu_model.tflite"
elif detector_config.type == "edgetpu":
model_config["path"] = "/edgetpu_model.tflite"
elif detector_config.type == "openvino":
for default_key, default_value in DEFAULT_MODEL.items():
model_config.setdefault(default_key, default_value)
model = ModelConfig.model_validate(model_config)
model.check_and_load_plus_model(self.plus_api, detector_config.type)
model.compute_model_hash()
labelmap_objects = model.merged_labelmap.values()
detector_config.model = model
self.detectors[key] = detector_config self.detectors[key] = detector_config
for name, camera in self.cameras.items(): for name, camera in self.cameras.items():
@@ -785,6 +811,21 @@ class FrigateConfig(FrigateBaseModel):
{"name": name, **merged_config} {"name": name, **merged_config}
) )
# resolve which named model this camera uses
if camera_config.detect.model is not None:
if camera_config.detect.model not in self.models:
raise ValueError(
f"Camera {name} references model '{camera_config.detect.model}' which is not defined under models. Defined models: {', '.join(self.models.keys())}"
)
elif len(self.models) == 1:
camera_config.detect.model = next(iter(self.models))
elif "default" in self.models:
camera_config.detect.model = "default"
else:
raise ValueError(
f"Camera {name} does not specify detect.model and multiple models are defined. Set detect.model on the camera or globally, or name one of the models 'default'."
)
if camera_config.ffmpeg.hwaccel_args == "auto": if camera_config.ffmpeg.hwaccel_args == "auto":
camera_config.ffmpeg.hwaccel_args = self.ffmpeg.hwaccel_args camera_config.ffmpeg.hwaccel_args = self.ffmpeg.hwaccel_args
@@ -1005,7 +1046,10 @@ class FrigateConfig(FrigateBaseModel):
verify_profile_overrides_match_base(camera_config) verify_profile_overrides_match_base(camera_config)
verify_autotrack_zones(camera_config) verify_autotrack_zones(camera_config)
verify_motion_and_detect(camera_config) verify_motion_and_detect(camera_config)
verify_objects_track(camera_config, labelmap_objects) verify_objects_track(
camera_config,
self.models[camera_config.detect.model].merged_labelmap.values(),
)
verify_lpr_and_face(self, camera_config) verify_lpr_and_face(self, camera_config)
# Validate camera profiles reference top-level profile definitions # Validate camera profiles reference top-level profile definitions
@@ -1022,8 +1066,11 @@ class FrigateConfig(FrigateBaseModel):
config.name = name config.name = name
self.objects.parse_all_objects(self.cameras) self.objects.parse_all_objects(self.cameras)
self.model.create_colormap(sorted(self.objects.all_objects)) for model in self.models.values():
self.model.check_and_load_plus_model(self.plus_api) model.create_colormap(sorted(self.objects.all_objects))
# expand detectors into per-model runtime instances
self.__build_detector_instances(raw_model_dumps)
# Check audio transcription and audio detection requirements # Check audio transcription and audio detection requirements
if self.audio_transcription.enabled: if self.audio_transcription.enabled:
@@ -1054,6 +1101,81 @@ class FrigateConfig(FrigateBaseModel):
return self return self
def __build_detector_instances(
self, raw_model_dumps: dict[str, dict[str, Any]]
) -> None:
"""Expand detector entries into runtime instances, one per assigned model."""
used_models = list(
dict.fromkeys(camera.detect.model for camera in self.cameras.values())
) or list(self.models.keys())
unused_models = set(self.models.keys()) - set(used_models)
if unused_models:
logger.warning(
f"Models {', '.join(sorted(unused_models))} are defined but not used by any camera, no detector instances will be created for them"
)
assignments = assign_detector_instances(
{key: detector.type for key, detector in self.detectors.items()},
used_models,
)
models_per_detector: dict[str, int] = {}
for _, detector_key, _ in assignments:
models_per_detector[detector_key] = (
models_per_detector.get(detector_key, 0) + 1
)
instances: dict[str, BaseDetectorConfig] = {}
for instance_name, detector_key, model_key in assignments:
instance = self.detectors[detector_key].model_copy(deep=True)
instance.model_key = model_key
model_dict = raw_model_dumps[model_key].copy()
if instance.model_path:
if models_per_detector[detector_key] > 1:
logger.warning(
f"Detector {detector_key} runs multiple models, its model_path will be ignored"
)
else:
model_dict["path"] = instance.model_path
if "path" not in model_dict:
if instance.type == "cpu" or instance.type.endswith("_tfl"):
model_dict["path"] = "/cpu_model.tflite"
elif instance.type == "edgetpu":
model_dict["path"] = "/edgetpu_model.tflite"
elif instance.type == "openvino":
for default_key, default_value in DEFAULT_MODEL.items():
model_dict.setdefault(default_key, default_value)
model = ModelConfig.model_validate(model_dict)
try:
model.check_and_load_plus_model(self.plus_api, instance.type)
except ValueError as e:
raise ValueError(f"Model '{model_key}': {e}") from e
model.compute_model_hash()
instance.model = model
instances[instance_name] = instance
logger.log(
logging.INFO if len(used_models) > 1 else logging.DEBUG,
f"Detector instance {instance_name} ({instance.type}) will run model '{model_key}'",
)
# populate user-facing detector entries with their first assigned
# model for display purposes
for instance_name, detector_key, model_key in assignments:
detector = self.detectors[detector_key]
if detector.model is None:
detector.model = instances[instance_name].model
detector.model_key = model_key
self._detector_instances = instances
@field_validator("cameras") @field_validator("cameras")
@classmethod @classmethod
def ensure_zones_and_cameras_have_different_names(cls, v: dict[str, CameraConfig]): def ensure_zones_and_cameras_have_different_names(cls, v: dict[str, CameraConfig]):
@@ -72,9 +72,10 @@ class LicensePlateProcessingMixin:
# Object config # Object config
self.lp_objects: list[str] = [] self.lp_objects: list[str] = []
for obj, attributes in self.config.model.attributes_map.items(): for model in self.config.models.values():
if "license_plate" in attributes: for obj, attributes in model.attributes_map.items():
self.lp_objects.append(obj) if "license_plate" in attributes and obj not in self.lp_objects:
self.lp_objects.append(obj)
# Detection specific parameters # Detection specific parameters
self.min_size = 8 self.min_size = 8
@@ -231,8 +231,12 @@ class ReviewDescriptionProcessor(PostProcessorApi):
final_data, final_data,
thumbs, thumbs,
camera_config.review.genai, camera_config.review.genai,
list(self.config.model.merged_labelmap.values()), list(
self.config.model.all_attributes, self.config.model_for_camera(
camera_config.name
).merged_labelmap.values()
),
self.config.model_for_camera(camera_config.name).all_attributes,
), ),
).start() ).start()
+59 -1
View File
@@ -1,11 +1,69 @@
import logging import logging
from .detector_config import InputTensorEnum, ModelConfig, PixelFormatEnum # noqa: F401 from .detector_config import InputTensorEnum, ModelConfig, PixelFormatEnum # noqa: F401
from .detector_types import DetectorConfig, DetectorTypeEnum, api_types # noqa: F401 from .detector_types import ( # noqa: F401
DetectorConfig,
DetectorTypeEnum,
api_types,
detector_supports_multiple_models,
)
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
def assign_detector_instances(
detector_types: dict[str, str],
used_models: list[str],
) -> list[tuple[str, str, str]]:
"""Assign detector entries to models.
Detector types that support multiple models get one instance per model.
Single-model detector entries are round-robin assigned across the models,
wrapping around so that every detector entry is assigned.
Args:
detector_types: Detector key to detector type, in config order
used_models: Ordered model keys in use by cameras
Returns:
List of (instance_name, detector_key, model_key) assignments
"""
multi = [
key
for key, type_key in detector_types.items()
if detector_supports_multiple_models(type_key)
]
single = [key for key in detector_types if key not in multi]
if not multi and len(single) < len(used_models):
single_types = sorted({detector_types[key] for key in single})
raise ValueError(
f"Detectors {', '.join(single)} (types: {', '.join(single_types)}) can each only run a single model, "
f"but {len(used_models)} models are in use ({', '.join(used_models)}). "
"Add more detectors, use a detector type that supports multiple models, or reduce the number of models assigned to cameras."
)
assignments: list[tuple[str, str, str]] = []
for key in multi:
for model_key in used_models:
instance_name = key if len(used_models) == 1 else f"{key}_{model_key}"
assignments.append((instance_name, key, model_key))
for i, key in enumerate(single):
assignments.append((key, key, used_models[i % len(used_models)]))
instance_names = [name for name, _, _ in assignments]
duplicates = {name for name in instance_names if instance_names.count(name) > 1}
if duplicates:
raise ValueError(
f"Detector instance names collide: {', '.join(sorted(duplicates))}. "
"Rename the conflicting detectors or models so that expanded instance names (detector_model) are unique."
)
return assignments
def create_detector(detector_config): def create_detector(detector_config):
if detector_config.type == DetectorTypeEnum.cpu: if detector_config.type == DetectorTypeEnum.cpu:
logger.warning( logger.warning(
+4
View File
@@ -11,6 +11,10 @@ logger = logging.getLogger(__name__)
class DetectionApi(ABC): class DetectionApi(ABC):
type_key: str type_key: str
supported_models: list[ModelTypeEnum] supported_models: list[ModelTypeEnum]
# whether this detector type can run multiple model instances concurrently
# on the same hardware (one detector config entry can be expanded to an
# instance per model); single-model detectors serve exactly one model each
supports_multiple_models: bool = False
@abstractmethod @abstractmethod
def __init__(self, detector_config: BaseDetectorConfig): def __init__(self, detector_config: BaseDetectorConfig):
+5
View File
@@ -250,6 +250,11 @@ class BaseDetectorConfig(BaseModel):
title="Detector specific model path", title="Detector specific model path",
description="File path to the detector model binary if required by the chosen detector.", description="File path to the detector model binary if required by the chosen detector.",
) )
model_key: str | None = Field(
default=None,
title="Assigned model name",
description="Name of the model (key under `models`) this detector instance serves. Set automatically at runtime, users should not set this.",
)
model_config = ConfigDict( model_config = ConfigDict(
extra="allow", arbitrary_types_allowed=True, protected_namespaces=() extra="allow", arbitrary_types_allowed=True, protected_namespaces=()
) )
+6
View File
@@ -29,6 +29,12 @@ for _, name, _ in _included_modules:
api_types = {det.type_key: det for det in DetectionApi.__subclasses__()} api_types = {det.type_key: det for det in DetectionApi.__subclasses__()}
def detector_supports_multiple_models(type_key: str) -> bool:
"""Return whether the given detector type can run multiple model instances."""
detector = api_types.get(type_key)
return bool(detector and getattr(detector, "supports_multiple_models", False))
class StrEnum(str, Enum): class StrEnum(str, Enum):
pass pass
+1
View File
@@ -37,6 +37,7 @@ class CpuDetectorConfig(BaseDetectorConfig):
class CpuTfl(DetectionApi): class CpuTfl(DetectionApi):
type_key = DETECTOR_KEY type_key = DETECTOR_KEY
supports_multiple_models = True
def __init__(self, detector_config: CpuDetectorConfig): def __init__(self, detector_config: CpuDetectorConfig):
# Suppress TFLite delegate creation messages that bypass Python logging # Suppress TFLite delegate creation messages that bypass Python logging
+1
View File
@@ -41,6 +41,7 @@ class ONNXDetectorConfig(BaseDetectorConfig):
class ONNXDetector(DetectionApi): class ONNXDetector(DetectionApi):
type_key = DETECTOR_KEY type_key = DETECTOR_KEY
supports_multiple_models = True
def __init__(self, detector_config: ONNXDetectorConfig): def __init__(self, detector_config: ONNXDetectorConfig):
super().__init__(detector_config) super().__init__(detector_config)
+1
View File
@@ -36,6 +36,7 @@ class OvDetectorConfig(BaseDetectorConfig):
class OvDetector(DetectionApi): class OvDetector(DetectionApi):
type_key = DETECTOR_KEY type_key = DETECTOR_KEY
supports_multiple_models = True
supported_models = [ supported_models = [
ModelTypeEnum.dfine, ModelTypeEnum.dfine,
ModelTypeEnum.rfdetr, ModelTypeEnum.rfdetr,
+1
View File
@@ -47,6 +47,7 @@ class RknnDetectorConfig(BaseDetectorConfig):
class Rknn(DetectionApi): class Rknn(DetectionApi):
type_key = DETECTOR_KEY type_key = DETECTOR_KEY
supports_multiple_models = True
def __init__(self, config: RknnDetectorConfig): def __init__(self, config: RknnDetectorConfig):
super().__init__(config) super().__init__(config)
+1
View File
@@ -30,6 +30,7 @@ class TeflonDetectorConfig(BaseDetectorConfig):
class TeflonTfl(DetectionApi): class TeflonTfl(DetectionApi):
type_key = DETECTOR_KEY type_key = DETECTOR_KEY
supports_multiple_models = True
def __init__(self, detector_config: TeflonDetectorConfig): def __init__(self, detector_config: TeflonDetectorConfig):
# Location in Debian's mesa-teflon-delegate # Location in Debian's mesa-teflon-delegate
+1
View File
@@ -82,6 +82,7 @@ class HostDeviceMem:
class TensorRtDetector(DetectionApi): class TensorRtDetector(DetectionApi):
type_key = DETECTOR_KEY type_key = DETECTOR_KEY
supports_multiple_models = True
def _load_engine(self, model_path): def _load_engine(self, model_path):
try: try:
+15 -6
View File
@@ -159,7 +159,16 @@ class EventProcessor(threading.Thread):
if width is None or height is None: if width is None or height is None:
return return
first_detector = list(self.config.detectors.values())[0] # find a detector instance running this camera's model so the
# event records the model that produced it
camera_detector = next(
(
detector
for detector in self.config.detector_instances.values()
if detector.model_key == camera_config.detect.model
),
list(self.config.detectors.values())[0],
)
start_time = event_data["start_time"] start_time = event_data["start_time"]
end_time = ( end_time = (
@@ -229,13 +238,13 @@ class EventProcessor(threading.Thread):
Event.thumbnail: event_data.get("thumbnail"), Event.thumbnail: event_data.get("thumbnail"),
Event.has_clip: event_data["has_clip"], Event.has_clip: event_data["has_clip"],
Event.has_snapshot: event_data["has_snapshot"], Event.has_snapshot: event_data["has_snapshot"],
Event.model_hash: first_detector.model.model_hash Event.model_hash: camera_detector.model.model_hash
if first_detector.model if camera_detector.model
else None, else None,
Event.model_type: first_detector.model.model_type Event.model_type: camera_detector.model.model_type
if first_detector.model if camera_detector.model
else None, else None,
Event.detector_type: first_detector.type, Event.detector_type: camera_detector.type,
Event.data: { Event.data: {
"box": box, "box": box,
"region": region, "region": region,
+8 -2
View File
@@ -436,7 +436,10 @@ class ReviewSegmentMaintainer(threading.Thread):
if not object["sub_label"]: if not object["sub_label"]:
segment.detections[object["id"]] = object["label"] segment.detections[object["id"]] = object["label"]
elif object["sub_label"][0] in self.config.model.all_attributes: elif (
object["sub_label"][0]
in self.config.model_for_camera(segment.camera).all_attributes
):
segment.detections[object["id"]] = object["sub_label"][0] segment.detections[object["id"]] = object["sub_label"][0]
else: else:
segment.detections[object["id"]] = f"{object['label']}-verified" segment.detections[object["id"]] = f"{object['label']}-verified"
@@ -574,7 +577,10 @@ class ReviewSegmentMaintainer(threading.Thread):
for object in activity.get_all_objects(): for object in activity.get_all_objects():
if not object["sub_label"]: if not object["sub_label"]:
detections[object["id"]] = object["label"] detections[object["id"]] = object["label"]
elif object["sub_label"][0] in self.config.model.all_attributes: elif (
object["sub_label"][0]
in self.config.model_for_camera(camera).all_attributes
):
detections[object["id"]] = object["sub_label"][0] detections[object["id"]] = object["sub_label"][0]
else: else:
detections[object["id"]] = f"{object['label']}-verified" detections[object["id"]] = f"{object['label']}-verified"
+181 -9
View File
@@ -86,7 +86,7 @@ class TestConfig(unittest.TestCase):
}, },
}, },
# needs to be a file that will exist, doesn't matter what # needs to be a file that will exist, doesn't matter what
"model": {"path": "/etc/hosts", "width": 512}, "models": {"default": {"path": "/etc/hosts", "width": 512}},
} }
frigate_config = FrigateConfig(**(deep_merge(config, self.minimal))) frigate_config = FrigateConfig(**(deep_merge(config, self.minimal)))
@@ -103,7 +103,7 @@ class TestConfig(unittest.TestCase):
assert frigate_config.detectors["edgetpu"].device is None assert frigate_config.detectors["edgetpu"].device is None
assert frigate_config.detectors["openvino"].device is None assert frigate_config.detectors["openvino"].device is None
assert frigate_config.model.path == "/etc/hosts" assert frigate_config.models["default"].path == "/etc/hosts"
assert frigate_config.detectors["cpu"].model.path == "/cpu_model.tflite" assert frigate_config.detectors["cpu"].model.path == "/cpu_model.tflite"
assert frigate_config.detectors["edgetpu"].model.path == "/edgetpu_model.tflite" assert frigate_config.detectors["edgetpu"].model.path == "/edgetpu_model.tflite"
assert frigate_config.detectors["openvino"].model.path == "/etc/hosts" assert frigate_config.detectors["openvino"].model.path == "/etc/hosts"
@@ -956,7 +956,7 @@ class TestConfig(unittest.TestCase):
def test_merge_labelmap(self): def test_merge_labelmap(self):
config = { config = {
"mqtt": {"host": "mqtt"}, "mqtt": {"host": "mqtt"},
"model": {"labelmap": {7: "truck"}}, "models": {"default": {"labelmap": {7: "truck"}}},
"cameras": { "cameras": {
"back": { "back": {
"ffmpeg": { "ffmpeg": {
@@ -977,7 +977,7 @@ class TestConfig(unittest.TestCase):
} }
frigate_config = FrigateConfig(**config) frigate_config = FrigateConfig(**config)
assert frigate_config.model.merged_labelmap[7] == "truck" assert frigate_config.models["default"].merged_labelmap[7] == "truck"
def test_default_labelmap_empty(self): def test_default_labelmap_empty(self):
config = { config = {
@@ -1002,12 +1002,12 @@ class TestConfig(unittest.TestCase):
} }
frigate_config = FrigateConfig(**config) frigate_config = FrigateConfig(**config)
assert frigate_config.model.merged_labelmap[0] == "person" assert frigate_config.models["default"].merged_labelmap[0] == "person"
def test_default_labelmap(self): def test_default_labelmap(self):
config = { config = {
"mqtt": {"host": "mqtt"}, "mqtt": {"host": "mqtt"},
"model": {"width": 320, "height": 320}, "models": {"default": {"width": 320, "height": 320}},
"cameras": { "cameras": {
"back": { "back": {
"ffmpeg": { "ffmpeg": {
@@ -1028,7 +1028,7 @@ class TestConfig(unittest.TestCase):
} }
frigate_config = FrigateConfig(**config) frigate_config = FrigateConfig(**config)
assert frigate_config.model.merged_labelmap[0] == "person" assert frigate_config.models["default"].merged_labelmap[0] == "person"
def test_plus_labelmap(self): def test_plus_labelmap(self):
with open(os.path.join(MODEL_CACHE_DIR, "test"), "w") as f: with open(os.path.join(MODEL_CACHE_DIR, "test"), "w") as f:
@@ -1039,7 +1039,7 @@ class TestConfig(unittest.TestCase):
config = { config = {
"mqtt": {"host": "mqtt"}, "mqtt": {"host": "mqtt"},
"detectors": {"cpu": {"type": "cpu"}}, "detectors": {"cpu": {"type": "cpu"}},
"model": {"path": "plus://test"}, "models": {"default": {"path": "plus://test"}},
"cameras": { "cameras": {
"back": { "back": {
"ffmpeg": { "ffmpeg": {
@@ -1060,7 +1060,7 @@ class TestConfig(unittest.TestCase):
} }
frigate_config = FrigateConfig(**config) frigate_config = FrigateConfig(**config)
assert frigate_config.model.merged_labelmap[0] == "amazon" assert frigate_config.models["default"].merged_labelmap[0] == "amazon"
def test_fails_on_invalid_role(self): def test_fails_on_invalid_role(self):
config = { config = {
@@ -1765,5 +1765,177 @@ class TestAttributeFilterDefaults(unittest.TestCase):
self.assertEqual(face_filter.min_score, 0.3) self.assertEqual(face_filter.min_score, 0.3)
class TestMultiModelConfig(unittest.TestCase):
"""Tests for named models and detector instance assignment."""
def setUp(self):
self.base = {
"mqtt": {"host": "mqtt"},
"models": {
"indoor": {"width": 320, "height": 320},
"outdoor": {"width": 640, "height": 640},
},
"cameras": {
"living_room": self._camera("indoor"),
"driveway": self._camera("outdoor"),
},
}
def _camera(self, model=None):
camera = {
"ffmpeg": {
"inputs": [{"path": "rtsp://10.0.0.1:554/video", "roles": ["detect"]}]
},
"detect": {"height": 1080, "width": 1920, "fps": 5},
}
if model:
camera["detect"]["model"] = model
return camera
def test_single_model_resolves_implicitly(self):
config = FrigateConfig(
mqtt={"host": "mqtt"},
models={"custom": {"width": 320, "height": 320}},
cameras={"back": self._camera()},
)
assert config.cameras["back"].detect.model == "custom"
def test_multiple_models_resolve_to_default(self):
config = FrigateConfig(
mqtt={"host": "mqtt"},
models={
"default": {"width": 320, "height": 320},
"outdoor": {"width": 640, "height": 640},
},
cameras={"back": self._camera()},
)
assert config.cameras["back"].detect.model == "default"
def test_multiple_models_without_default_requires_selection(self):
config = self.base.copy()
config["cameras"] = {"back": self._camera()}
self.assertRaises(ValidationError, lambda: FrigateConfig(**config))
def test_camera_references_missing_model(self):
config = self.base.copy()
config["cameras"] = {"back": self._camera("thermal")}
self.assertRaises(ValidationError, lambda: FrigateConfig(**config))
def test_global_detect_model_inherited_and_overridden(self):
config = self.base.copy()
config["detect"] = {"model": "indoor"}
config["cameras"] = {
"living_room": self._camera(),
"driveway": self._camera("outdoor"),
}
frigate_config = FrigateConfig(**config)
assert frigate_config.cameras["living_room"].detect.model == "indoor"
assert frigate_config.cameras["driveway"].detect.model == "outdoor"
def test_invalid_model_name(self):
config = self.base.copy()
config["models"] = {"bad name!": {"width": 320, "height": 320}}
self.assertRaises(ValidationError, lambda: FrigateConfig(**config))
def test_multi_model_detector_expands_instances(self):
config = self.base.copy()
config["detectors"] = {
"ov0": {"type": "openvino", "device": "GPU"},
"ov1": {"type": "openvino", "device": "GPU.1"},
}
frigate_config = FrigateConfig(**config)
assert sorted(frigate_config.detector_instances.keys()) == [
"ov0_indoor",
"ov0_outdoor",
"ov1_indoor",
"ov1_outdoor",
]
assert frigate_config.detector_instances["ov0_indoor"].model_key == "indoor"
assert frigate_config.detector_instances["ov0_indoor"].model.width == 320
assert frigate_config.detector_instances["ov0_outdoor"].model.width == 640
def test_multi_model_detector_single_model_keeps_name(self):
config = self.base.copy()
config["models"] = {"default": {"width": 320, "height": 320}}
config["cameras"] = {"back": self._camera()}
config["detectors"] = {"ov": {"type": "openvino", "device": "GPU"}}
frigate_config = FrigateConfig(**config)
assert list(frigate_config.detector_instances.keys()) == ["ov"]
assert frigate_config.detector_instances["ov"].model_key == "default"
def test_single_model_detectors_round_robin(self):
config = self.base.copy()
config["detectors"] = {
"coral0": {"type": "edgetpu", "device": "usb:0"},
"coral1": {"type": "edgetpu", "device": "usb:1"},
"coral2": {"type": "edgetpu", "device": "usb:2"},
}
frigate_config = FrigateConfig(**config)
assignments = {
key: instance.model_key
for key, instance in frigate_config.detector_instances.items()
}
assert assignments == {
"coral0": "indoor",
"coral1": "outdoor",
"coral2": "indoor",
}
def test_single_model_detectors_insufficient_coverage(self):
config = self.base.copy()
config["detectors"] = {"coral": {"type": "edgetpu", "device": "usb"}}
self.assertRaises(ValidationError, lambda: FrigateConfig(**config))
def test_single_model_detector_with_multi_model_detector(self):
config = self.base.copy()
config["detectors"] = {
"coral": {"type": "edgetpu", "device": "usb"},
"ov": {"type": "openvino", "device": "GPU"},
}
frigate_config = FrigateConfig(**config)
assert frigate_config.detector_instances["coral"].model_key == "indoor"
assert frigate_config.detector_instances["ov_indoor"].model_key == "indoor"
assert frigate_config.detector_instances["ov_outdoor"].model_key == "outdoor"
def test_unused_model_gets_no_instances(self):
config = self.base.copy()
config["models"] = {
**config["models"],
"thermal": {"width": 320, "height": 320},
}
frigate_config = FrigateConfig(**config)
model_keys = {
instance.model_key
for instance in frigate_config.detector_instances.values()
}
assert "thermal" not in model_keys
def test_model_path_ignored_when_detector_runs_multiple_models(self):
config = self.base.copy()
config["detectors"] = {
"cpu": {"type": "cpu", "model_path": "/custom_model.tflite"}
}
frigate_config = FrigateConfig(**config)
assert (
frigate_config.detector_instances["cpu_indoor"].model.path
== "/cpu_model.tflite"
)
def test_model_path_applied_when_detector_runs_one_model(self):
config = self.base.copy()
config["models"] = {"default": {"width": 320, "height": 320}}
config["cameras"] = {"back": self._camera()}
config["detectors"] = {
"cpu": {"type": "cpu", "model_path": "/custom_model.tflite"}
}
frigate_config = FrigateConfig(**config)
assert (
frigate_config.detector_instances["cpu"].model.path
== "/custom_model.tflite"
)
if __name__ == "__main__": if __name__ == "__main__":
unittest.main(verbosity=2) unittest.main(verbosity=2)
+42
View File
@@ -0,0 +1,42 @@
"""Tests for config file migration functions."""
import unittest
from frigate.util.config import migrate_019_0
class TestMigrate019(unittest.TestCase):
def test_migrates_model_to_named_models(self):
config = {
"version": "0.18-0",
"mqtt": {"host": "mqtt"},
"model": {"path": "/config/model.tflite", "width": 320, "height": 320},
}
new_config = migrate_019_0(config)
assert "model" not in new_config
assert new_config["models"] == {
"default": {"path": "/config/model.tflite", "width": 320, "height": 320}
}
assert new_config["version"] == "0.19-0"
def test_no_model_defined(self):
config = {"version": "0.18-0", "mqtt": {"host": "mqtt"}}
new_config = migrate_019_0(config)
assert "model" not in new_config
assert "models" not in new_config
assert new_config["version"] == "0.19-0"
def test_existing_models_not_overwritten(self):
config = {
"version": "0.18-0",
"model": {"width": 320},
"models": {"custom": {"width": 640}},
}
new_config = migrate_019_0(config)
assert "model" not in new_config
assert new_config["models"] == {"custom": {"width": 640}}
assert new_config["version"] == "0.19-0"
if __name__ == "__main__":
unittest.main(verbosity=2)
+4 -1
View File
@@ -209,7 +209,10 @@ class TrackedObjectProcessor(threading.Thread):
if obj.obj_data.get("sub_label"): if obj.obj_data.get("sub_label"):
sub_label = obj.obj_data["sub_label"][0] sub_label = obj.obj_data["sub_label"][0]
if sub_label in self.config.model.all_attribute_logos: if (
sub_label
in self.config.model_for_camera(camera).all_attribute_logos
):
self.dispatcher.publish( self.dispatcher.publish(
f"{camera}/{sub_label}/snapshot", f"{camera}/{sub_label}/snapshot",
jpg_bytes, jpg_bytes,
+29 -1
View File
@@ -20,7 +20,7 @@ from frigate.util.services import get_video_properties
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
CURRENT_CONFIG_VERSION = "0.18-0" CURRENT_CONFIG_VERSION = "0.19-0"
DEFAULT_CONFIG_FILE = os.path.join(CONFIG_DIR, "config.yml") DEFAULT_CONFIG_FILE = os.path.join(CONFIG_DIR, "config.yml")
@@ -99,6 +99,7 @@ def migrate_frigate_config(config_file: str):
new_config = migrate_014(config) new_config = migrate_014(config)
with open(config_file, "w") as f: with open(config_file, "w") as f:
yaml.dump(new_config, f) yaml.dump(new_config, f)
config = new_config
previous_version = "0.14" previous_version = "0.14"
logger.info("Migrating export file names...") logger.info("Migrating export file names...")
@@ -117,6 +118,7 @@ def migrate_frigate_config(config_file: str):
new_config = migrate_015_0(config) new_config = migrate_015_0(config)
with open(config_file, "w") as f: with open(config_file, "w") as f:
yaml.dump(new_config, f) yaml.dump(new_config, f)
config = new_config
previous_version = "0.15-0" previous_version = "0.15-0"
if previous_version < "0.15-1": if previous_version < "0.15-1":
@@ -124,6 +126,7 @@ def migrate_frigate_config(config_file: str):
new_config = migrate_015_1(config) new_config = migrate_015_1(config)
with open(config_file, "w") as f: with open(config_file, "w") as f:
yaml.dump(new_config, f) yaml.dump(new_config, f)
config = new_config
previous_version = "0.15-1" previous_version = "0.15-1"
if previous_version < "0.16-0": if previous_version < "0.16-0":
@@ -131,6 +134,7 @@ def migrate_frigate_config(config_file: str):
new_config = migrate_016_0(config) new_config = migrate_016_0(config)
with open(config_file, "w") as f: with open(config_file, "w") as f:
yaml.dump(new_config, f) yaml.dump(new_config, f)
config = new_config
previous_version = "0.16-0" previous_version = "0.16-0"
if previous_version < "0.17-0": if previous_version < "0.17-0":
@@ -138,6 +142,7 @@ def migrate_frigate_config(config_file: str):
new_config = migrate_017_0(config) new_config = migrate_017_0(config)
with open(config_file, "w") as f: with open(config_file, "w") as f:
yaml.dump(new_config, f) yaml.dump(new_config, f)
config = new_config
previous_version = "0.17-0" previous_version = "0.17-0"
if previous_version < "0.18-0": if previous_version < "0.18-0":
@@ -145,8 +150,17 @@ def migrate_frigate_config(config_file: str):
new_config = migrate_018_0(config) new_config = migrate_018_0(config)
with open(config_file, "w") as f: with open(config_file, "w") as f:
yaml.dump(new_config, f) yaml.dump(new_config, f)
config = new_config
previous_version = "0.18-0" previous_version = "0.18-0"
if previous_version < "0.19-0":
logger.info(f"Migrating frigate config from {previous_version} to 0.19-0...")
new_config = migrate_019_0(config)
with open(config_file, "w") as f:
yaml.dump(new_config, f)
config = new_config
previous_version = "0.19-0"
logger.info("Finished frigate config migration...") logger.info("Finished frigate config migration...")
@@ -658,6 +672,20 @@ def migrate_018_0(config: dict[str, dict[str, Any]]) -> dict[str, dict[str, Any]
return new_config return new_config
def migrate_019_0(config: dict[str, dict[str, Any]]) -> dict[str, dict[str, Any]]:
"""Handle migrating frigate config to 0.19-0"""
new_config = config.copy()
# Migrate the single model config to named models
model = new_config.pop("model", None)
if model is not None and "models" not in new_config:
new_config["models"] = {"default": model}
new_config["version"] = "0.19-0"
return new_config
def get_relative_coordinates( def get_relative_coordinates(
mask: str | list | None, mask: str | list | None,
frame_shape: tuple[int, int], frame_shape: tuple[int, int],
+1 -1
View File
@@ -1 +1 @@
[{"id": "case-001", "name": "Package Theft Investigation", "description": "Review of suspicious activity near the front porch", "created_at": 1780597809.365581, "updated_at": 1780673409.365581}] [{"id": "case-001", "name": "Package Theft Investigation", "description": "Review of suspicious activity near the front porch", "created_at": 1784761296.1184616, "updated_at": 1784836896.1184616}]
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -1 +1 @@
[{"id": "event-person-001", "label": "person", "sub_label": null, "camera": "front_door", "start_time": 1780677009.365581, "end_time": 1780677039.365581, "false_positive": false, "zones": ["front_yard"], "thumbnail": null, "has_clip": true, "has_snapshot": true, "retain_indefinitely": false, "plus_id": null, "model_hash": "abc123", "detector_type": "cpu", "model_type": "ssd", "data": {"top_score": 0.92, "score": 0.92, "region": [0.1, 0.1, 0.5, 0.8], "box": [0.2, 0.15, 0.45, 0.75], "area": 0.18, "ratio": 0.6, "type": "object", "description": "A person walking toward the front door", "average_estimated_speed": 1.2, "velocity_angle": 45.0, "path_data": [[[0.2, 0.5], 0.0], [[0.3, 0.5], 1.0]]}}, {"id": "event-car-001", "label": "car", "sub_label": null, "camera": "backyard", "start_time": 1780673409.365581, "end_time": 1780673454.365581, "false_positive": false, "zones": ["driveway"], "thumbnail": null, "has_clip": true, "has_snapshot": true, "retain_indefinitely": false, "plus_id": null, "model_hash": "def456", "detector_type": "cpu", "model_type": "ssd", "data": {"top_score": 0.87, "score": 0.87, "region": [0.3, 0.2, 0.9, 0.7], "box": [0.35, 0.25, 0.85, 0.65], "area": 0.2, "ratio": 1.25, "type": "object", "description": "A car parked in the driveway", "average_estimated_speed": 0.0, "velocity_angle": 0.0, "path_data": []}}, {"id": "event-person-002", "label": "person", "sub_label": null, "camera": "garage", "start_time": 1780669809.365581, "end_time": 1780669829.365581, "false_positive": false, "zones": [], "thumbnail": null, "has_clip": false, "has_snapshot": true, "retain_indefinitely": false, "plus_id": null, "model_hash": "ghi789", "detector_type": "cpu", "model_type": "ssd", "data": {"top_score": 0.78, "score": 0.78, "region": [0.0, 0.0, 0.6, 0.9], "box": [0.1, 0.05, 0.5, 0.85], "area": 0.32, "ratio": 0.5, "type": "object", "description": null, "average_estimated_speed": 0.5, "velocity_angle": 90.0, "path_data": [[[0.1, 0.4], 0.0]]}}] [{"id": "event-person-001", "label": "person", "sub_label": null, "camera": "front_door", "start_time": 1784840496.1184616, "end_time": 1784840526.1184616, "false_positive": false, "zones": ["front_yard"], "thumbnail": null, "has_clip": true, "has_snapshot": true, "retain_indefinitely": false, "plus_id": null, "model_hash": "abc123", "detector_type": "cpu", "model_type": "ssd", "data": {"top_score": 0.92, "score": 0.92, "region": [0.1, 0.1, 0.5, 0.8], "box": [0.2, 0.15, 0.45, 0.75], "area": 0.18, "ratio": 0.6, "type": "object", "description": "A person walking toward the front door", "average_estimated_speed": 1.2, "velocity_angle": 45.0, "path_data": [[[0.2, 0.5], 0.0], [[0.3, 0.5], 1.0]]}}, {"id": "event-car-001", "label": "car", "sub_label": null, "camera": "backyard", "start_time": 1784836896.1184616, "end_time": 1784836941.1184616, "false_positive": false, "zones": ["driveway"], "thumbnail": null, "has_clip": true, "has_snapshot": true, "retain_indefinitely": false, "plus_id": null, "model_hash": "def456", "detector_type": "cpu", "model_type": "ssd", "data": {"top_score": 0.87, "score": 0.87, "region": [0.3, 0.2, 0.9, 0.7], "box": [0.35, 0.25, 0.85, 0.65], "area": 0.2, "ratio": 1.25, "type": "object", "description": "A car parked in the driveway", "average_estimated_speed": 0.0, "velocity_angle": 0.0, "path_data": []}}, {"id": "event-person-002", "label": "person", "sub_label": null, "camera": "garage", "start_time": 1784833296.1184616, "end_time": 1784833316.1184616, "false_positive": false, "zones": [], "thumbnail": null, "has_clip": false, "has_snapshot": true, "retain_indefinitely": false, "plus_id": null, "model_hash": "ghi789", "detector_type": "cpu", "model_type": "ssd", "data": {"top_score": 0.78, "score": 0.78, "region": [0.0, 0.0, 0.6, 0.9], "box": [0.1, 0.05, 0.5, 0.85], "area": 0.32, "ratio": 0.5, "type": "object", "description": null, "average_estimated_speed": 0.5, "velocity_angle": 90.0, "path_data": [[[0.1, 0.4], 0.0]]}}]
+1 -1
View File
@@ -1 +1 @@
[{"id": "export-001", "camera": "front_door", "name": "Front Door - Person Alert", "date": 1780680609.365581, "video_path": "/exports/export-001.mp4", "thumb_path": "/exports/export-001-thumb.jpg", "in_progress": false, "export_case_id": null}, {"id": "export-002", "camera": "backyard", "name": "Backyard - Car Detection", "date": 1780673409.365581, "video_path": "/exports/export-002.mp4", "thumb_path": "/exports/export-002-thumb.jpg", "in_progress": false, "export_case_id": "case-001"}, {"id": "export-003", "camera": "garage", "name": "Garage - In Progress", "date": 1780682409.365581, "video_path": "/exports/export-003.mp4", "thumb_path": "/exports/export-003-thumb.jpg", "in_progress": true, "export_case_id": null}] [{"id": "export-001", "camera": "front_door", "name": "Front Door - Person Alert", "date": 1784844096.1184616, "video_path": "/exports/export-001.mp4", "thumb_path": "/exports/export-001-thumb.jpg", "in_progress": false, "export_case_id": null}, {"id": "export-002", "camera": "backyard", "name": "Backyard - Car Detection", "date": 1784836896.1184616, "video_path": "/exports/export-002.mp4", "thumb_path": "/exports/export-002-thumb.jpg", "in_progress": false, "export_case_id": "case-001"}, {"id": "export-003", "camera": "garage", "name": "Garage - In Progress", "date": 1784845896.1184616, "video_path": "/exports/export-003.mp4", "thumb_path": "/exports/export-003-thumb.jpg", "in_progress": true, "export_case_id": null}]
@@ -102,11 +102,17 @@ def generate_config():
snapshot = config.model_dump() snapshot = config.model_dump()
# Runtime-computed fields not in the Pydantic dump # Runtime-computed fields not in the Pydantic dump
all_attrs = set() for model_dict in snapshot.get("models", {}).values():
for attrs in snapshot.get("model", {}).get("attributes_map", {}).values(): all_attrs = set()
all_attrs.update(attrs) for attrs in model_dict.get("attributes_map", {}).values():
snapshot["model"]["all_attributes"] = sorted(all_attrs) all_attrs.update(attrs)
snapshot["model"]["colormap"] = {} model_dict["all_attributes"] = sorted(all_attrs)
model_dict["colormap"] = {}
# legacy single-model block mirrors the default model, matching /api/config
models = snapshot.get("models", {})
default_key = "default" if "default" in models else next(iter(models))
snapshot["model"] = models[default_key]
return snapshot return snapshot
@@ -1 +1 @@
{"2026-06-05": {"day": "2026-06-05", "reviewed_alert": 1, "reviewed_detection": 0, "total_alert": 2, "total_detection": 2}, "2026-06-04": {"day": "2026-06-04", "reviewed_alert": 3, "reviewed_detection": 2, "total_alert": 3, "total_detection": 4}} {"2026-07-23": {"day": "2026-07-23", "reviewed_alert": 1, "reviewed_detection": 0, "total_alert": 2, "total_detection": 2}, "2026-07-22": {"day": "2026-07-22", "reviewed_alert": 3, "reviewed_detection": 2, "total_alert": 3, "total_detection": 4}}
+1 -1
View File
@@ -1 +1 @@
[{"id": "review-alert-001", "camera": "front_door", "start_time": "2026-06-05T11:30:09.365581", "end_time": "2026-06-05T11:30:39.365581", "has_been_reviewed": false, "severity": "alert", "thumb_path": "/clips/front_door/review-alert-001-thumb.jpg", "data": {"audio": [], "detections": ["person-abc123"], "objects": ["person"], "sub_labels": [], "significant_motion_areas": [], "zones": ["front_yard"]}}, {"id": "review-alert-002", "camera": "backyard", "start_time": "2026-06-05T10:30:09.365581", "end_time": "2026-06-05T10:30:54.365581", "has_been_reviewed": true, "severity": "alert", "thumb_path": "/clips/backyard/review-alert-002-thumb.jpg", "data": {"audio": [], "detections": ["car-def456"], "objects": ["car"], "sub_labels": [], "significant_motion_areas": [], "zones": ["driveway"]}}, {"id": "review-detect-001", "camera": "garage", "start_time": "2026-06-05T09:30:09.365581", "end_time": "2026-06-05T09:30:29.365581", "has_been_reviewed": false, "severity": "detection", "thumb_path": "/clips/garage/review-detect-001-thumb.jpg", "data": {"audio": [], "detections": ["person-ghi789"], "objects": ["person"], "sub_labels": [], "significant_motion_areas": [], "zones": []}}, {"id": "review-detect-002", "camera": "front_door", "start_time": "2026-06-05T08:30:09.365581", "end_time": "2026-06-05T08:30:24.365581", "has_been_reviewed": false, "severity": "detection", "thumb_path": "/clips/front_door/review-detect-002-thumb.jpg", "data": {"audio": [], "detections": ["car-jkl012"], "objects": ["car"], "sub_labels": [], "significant_motion_areas": [], "zones": ["front_yard"]}}] [{"id": "review-alert-001", "camera": "front_door", "start_time": "2026-07-23T21:01:36.118462", "end_time": "2026-07-23T21:02:06.118462", "has_been_reviewed": false, "severity": "alert", "thumb_path": "/clips/front_door/review-alert-001-thumb.jpg", "data": {"audio": [], "detections": ["person-abc123"], "objects": ["person"], "sub_labels": [], "significant_motion_areas": [], "zones": ["front_yard"]}}, {"id": "review-alert-002", "camera": "backyard", "start_time": "2026-07-23T20:01:36.118462", "end_time": "2026-07-23T20:02:21.118462", "has_been_reviewed": true, "severity": "alert", "thumb_path": "/clips/backyard/review-alert-002-thumb.jpg", "data": {"audio": [], "detections": ["car-def456"], "objects": ["car"], "sub_labels": [], "significant_motion_areas": [], "zones": ["driveway"]}}, {"id": "review-detect-001", "camera": "garage", "start_time": "2026-07-23T19:01:36.118462", "end_time": "2026-07-23T19:01:56.118462", "has_been_reviewed": false, "severity": "detection", "thumb_path": "/clips/garage/review-detect-001-thumb.jpg", "data": {"audio": [], "detections": ["person-ghi789"], "objects": ["person"], "sub_labels": [], "significant_motion_areas": [], "zones": []}}, {"id": "review-detect-002", "camera": "front_door", "start_time": "2026-07-23T18:01:36.118462", "end_time": "2026-07-23T18:01:51.118462", "has_been_reviewed": false, "severity": "detection", "thumb_path": "/clips/front_door/review-detect-002-thumb.jpg", "data": {"audio": [], "detections": ["car-jkl012"], "objects": ["car"], "sub_labels": [], "significant_motion_areas": [], "zones": ["front_yard"]}}]
@@ -86,6 +86,10 @@
"label": "Enable object detection", "label": "Enable object detection",
"description": "Enable or disable object detection for this camera." "description": "Enable or disable object detection for this camera."
}, },
"model": {
"label": "Detection model name",
"description": "Name of the model (key under `models`) used by this camera. Defaults to the only defined model, or the model named 'default'."
},
"height": { "height": {
"label": "Detect height", "label": "Detect height",
"description": "Height (pixels) of frames used for the detect stream; leave empty to use the native stream resolution." "description": "Height (pixels) of frames used for the detect stream; leave empty to use the native stream resolution."
+11 -3
View File
@@ -329,6 +329,10 @@
"label": "Detector specific model path", "label": "Detector specific model path",
"description": "File path to the detector model binary if required by the chosen detector." "description": "File path to the detector model binary if required by the chosen detector."
}, },
"model_key": {
"label": "Assigned model name",
"description": "Name of the model (key under `models`) this detector instance serves. Set automatically at runtime, users should not set this."
},
"axengine": { "axengine": {
"label": "AXEngine NPU", "label": "AXEngine NPU",
"description": "AXERA AX650N/AX8850N NPU detector running compiled .axmodel files via the AXEngine runtime." "description": "AXERA AX650N/AX8850N NPU detector running compiled .axmodel files via the AXEngine runtime."
@@ -454,9 +458,9 @@
} }
} }
}, },
"model": { "models": {
"label": "Detection model", "label": "Detection models",
"description": "Settings to configure a custom object detection model and its input shape.", "description": "Named object detection models. Cameras select a model with detect.model; detectors are assigned to models automatically.",
"path": { "path": {
"label": "Custom object detector model path", "label": "Custom object detector model path",
"description": "Path to a custom detection model file (or plus://<model_id> for Frigate+ models)." "description": "Path to a custom detection model file (or plus://<model_id> for Frigate+ models)."
@@ -625,6 +629,10 @@
"label": "Enable object detection", "label": "Enable object detection",
"description": "Enable or disable object detection for all cameras; can be overridden per-camera." "description": "Enable or disable object detection for all cameras; can be overridden per-camera."
}, },
"model": {
"label": "Detection model name",
"description": "Name of the model (key under `models`) used by this camera. Defaults to the only defined model, or the model named 'default'."
},
"height": { "height": {
"label": "Detect height", "label": "Detect height",
"description": "Height (pixels) of frames used for the detect stream; leave empty to use the native stream resolution." "description": "Height (pixels) of frames used for the detect stream; leave empty to use the native stream resolution."
@@ -74,6 +74,7 @@ const SECTIONS_WITHOUT_OVERRIDE_BADGE = new Set([
"birdseye", "birdseye",
"detectors", "detectors",
"model", "model",
"models",
]); ]);
type CameraEntryProps = { type CameraEntryProps = {
+11 -1
View File
@@ -70,7 +70,17 @@ export function extractSectionSchema(
// For global level, get from root properties // For global level, get from root properties
if (schemaObj.properties) { if (schemaObj.properties) {
const props = schemaObj.properties; const props = schemaObj.properties;
const sectionProp = props[sectionPath]; let sectionProp = props[sectionPath];
// the model editor edits a single entry of the `models` map, so
// resolve the map value schema since there is no root `model` property
if (!sectionProp && sectionPath === "model") {
const modelsProp = props["models"] as SchemaWithDefinitions | undefined;
const additional = modelsProp?.additionalProperties;
if (additional && typeof additional === "object") {
sectionProp = additional as RJSFSchema;
}
}
if (sectionProp && typeof sectionProp === "object") { if (sectionProp && typeof sectionProp === "object") {
if ("$ref" in sectionProp && typeof sectionProp.$ref === "string") { if ("$ref" in sectionProp && typeof sectionProp.$ref === "string") {
+30 -23
View File
@@ -59,6 +59,7 @@ export interface CameraConfig {
height: number; height: number;
max_disappeared: number; max_disappeared: number;
min_initialized: number; min_initialized: number;
model: string;
stationary: { stationary: {
interval: number; interval: number;
max_frames: { max_frames: {
@@ -394,6 +395,30 @@ export type GenAIAgentConfig = {
runtime_options?: Record<string, unknown>; runtime_options?: Record<string, unknown>;
}; };
export interface ModelConfig {
height: number;
input_pixel_format: string;
input_tensor: string;
labelmap: Record<string, unknown>;
labelmap_path: string | null;
model_type: string;
path: string | null;
width: number;
colormap: { [key: string]: [number, number, number] };
attributes_map: { [key: string]: string[] };
all_attributes: string[];
plus?: {
name: string;
id: string;
trainDate: string;
baseModel: string;
isBaseModel: boolean;
supportedDetectors: string[];
width: number;
height: number;
} | null;
}
export interface FrigateConfig { export interface FrigateConfig {
version: string; version: string;
safe_mode: boolean; safe_mode: boolean;
@@ -446,6 +471,7 @@ export interface FrigateConfig {
height: number | null; height: number | null;
max_disappeared: number | null; max_disappeared: number | null;
min_initialized: number | null; min_initialized: number | null;
model: string | null;
stationary: { stationary: {
interval: number | null; interval: number | null;
max_frames: { max_frames: {
@@ -512,29 +538,10 @@ export interface FrigateConfig {
logs: Record<string, string>; logs: Record<string, string>;
}; };
model: { // legacy single-model block, mirrors the default entry of `models`
height: number; model: ModelConfig;
input_pixel_format: string;
input_tensor: string; models: { [modelKey: string]: ModelConfig };
labelmap: Record<string, unknown>;
labelmap_path: string | null;
model_type: string;
path: string | null;
width: number;
colormap: { [key: string]: [number, number, number] };
attributes_map: { [key: string]: string[] };
all_attributes: string[];
plus?: {
name: string;
id: string;
trainDate: string;
baseModel: string;
isBaseModel: boolean;
supportedDetectors: string[];
width: number;
height: number;
} | null;
};
motion: Record<string, unknown> | null; motion: Record<string, unknown> | null;
@@ -115,8 +115,10 @@ const STATUS_BAR_KEY = "detectors_and_model";
const EMPTY_PENDING: Record<string, ConfigSectionData> = {}; const EMPTY_PENDING: Record<string, ConfigSectionData> = {};
const deriveInitialState = (config: FrigateConfig): PageState => { const deriveInitialState = (config: FrigateConfig): PageState => {
const plusModelId = config.model?.plus?.id; // this view edits the default model; other named models are untouched
const modelPath = config.model?.path; const defaultModel = config.models?.default ?? config.model;
const plusModelId = defaultModel?.plus?.id;
const modelPath = defaultModel?.path;
const plusEnabled = Boolean(config.plus?.enabled); const plusEnabled = Boolean(config.plus?.enabled);
// The reliable signal that a Plus model is currently active is the // The reliable signal that a Plus model is currently active is the
@@ -136,10 +138,8 @@ const deriveInitialState = (config: FrigateConfig): PageState => {
modelTab = "custom"; modelTab = "custom";
} }
const { plus: _plus, ...modelWithoutPlus } = (config.model ?? {}) as Record< const { plus: _plus, ...modelWithoutPlus } = (defaultModel ??
string, {}) as unknown as Record<string, unknown>;
unknown
>;
// If a Plus model is active, the resolved `model.path` is auto-derived from // If a Plus model is active, the resolved `model.path` is auto-derived from
// `plus.id` — drop it so the Custom tab starts clean and doesn't silently // `plus.id` — drop it so the Custom tab starts clean and doesn't silently
// re-save the same Plus model when the user thinks they switched modes. // re-save the same Plus model when the user thinks they switched modes.
@@ -476,7 +476,7 @@ export default function DetectorsAndModelSettingsView({
try { try {
await axios.put("config/set", { await axios.put("config/set", {
requires_restart: 0, requires_restart: 0,
config_data: { detectors: null, model: null }, config_data: { detectors: null, models: { default: null } },
}); });
preCleared = true; preCleared = true;
} catch { } catch {
@@ -488,7 +488,7 @@ export default function DetectorsAndModelSettingsView({
requires_restart: 0, requires_restart: 0,
config_data: { config_data: {
detectors: sanitizedDetectors, detectors: sanitizedDetectors,
model: modelPayload, models: { default: modelPayload },
}, },
}); });
@@ -541,7 +541,7 @@ export default function DetectorsAndModelSettingsView({
snapshot.detectors, snapshot.detectors,
detectorHiddenFields, detectorHiddenFields,
), ),
model: restoreModel, models: { default: restoreModel },
}, },
}); });
} catch { } catch {