2025-02-26 17:58:25 +03:00
from enum import Enum
2024-10-26 20:07:45 +03:00
from typing import Dict , List , Optional
2024-09-28 22:21:42 +03:00
2025-03-20 05:52:55 +03:00
from pydantic import ConfigDict , Field
2024-09-28 22:21:42 +03:00
from . base import FrigateBaseModel
2024-10-26 20:07:45 +03:00
__all__ = [
2025-03-19 18:02:40 +03:00
" CameraFaceRecognitionConfig " ,
" CameraLicensePlateRecognitionConfig " ,
2025-10-09 02:06:03 +03:00
" CameraAudioTranscriptionConfig " ,
2024-10-26 20:07:45 +03:00
" FaceRecognitionConfig " ,
" SemanticSearchConfig " ,
2025-07-07 17:03:57 +03:00
" CameraSemanticSearchConfig " ,
2024-10-26 20:07:45 +03:00
" LicensePlateRecognitionConfig " ,
]
2024-10-23 01:05:48 +03:00
2025-02-26 17:58:25 +03:00
class SemanticSearchModelEnum ( str , Enum ) :
jinav1 = " jinav1 "
jinav2 = " jinav2 "
2025-05-27 18:26:00 +03:00
class EnrichmentsDeviceEnum ( str , Enum ) :
2025-04-08 04:30:08 +03:00
GPU = " GPU "
CPU = " CPU "
2025-07-07 17:03:57 +03:00
class TriggerType ( str , Enum ) :
THUMBNAIL = " thumbnail "
DESCRIPTION = " description "
class TriggerAction ( str , Enum ) :
NOTIFICATION = " notification "
2025-10-29 00:13:04 +03:00
SUB_LABEL = " sub_label "
ATTRIBUTE = " attribute "
2025-07-07 17:03:57 +03:00
2025-07-18 17:28:02 +03:00
class ObjectClassificationType ( str , Enum ) :
sub_label = " sub_label "
attribute = " attribute "
2025-05-27 18:26:00 +03:00
class AudioTranscriptionConfig ( FrigateBaseModel ) :
2026-02-27 18:55:36 +03:00
enabled : bool = Field (
default = False ,
title = " Enable audio transcription " ,
description = " Enable or disable automatic audio transcription for all cameras; can be overridden per-camera. " ,
)
2025-05-27 18:26:00 +03:00
language : str = Field (
default = " en " ,
2026-02-27 18:55:36 +03:00
title = " Transcription language " ,
description = " Language code used for transcription/translation (for example ' en ' for English). See https://whisper-api.com/docs/languages/ for supported language codes. " ,
2025-05-27 18:26:00 +03:00
)
device : Optional [ EnrichmentsDeviceEnum ] = Field (
default = EnrichmentsDeviceEnum . CPU ,
2026-02-27 18:55:36 +03:00
title = " Transcription device " ,
description = " Device key (CPU/GPU) to run the transcription model on. Only NVIDIA CUDA GPUs are currently supported for transcription. " ,
2025-05-27 18:26:00 +03:00
)
model_size : str = Field (
2026-02-27 18:55:36 +03:00
default = " small " ,
title = " Model size " ,
description = " Model size to use for offline audio event transcription. " ,
2025-05-27 18:26:00 +03:00
)
live_enabled : Optional [ bool ] = Field (
2026-02-27 18:55:36 +03:00
default = False ,
title = " Live transcription " ,
description = " Enable streaming live transcription for audio as it is received. " ,
2025-05-27 18:26:00 +03:00
)
2025-01-13 18:09:04 +03:00
class BirdClassificationConfig ( FrigateBaseModel ) :
2026-02-27 18:55:36 +03:00
enabled : bool = Field (
default = False ,
title = " Bird classification " ,
description = " Enable or disable bird classification. " ,
)
2025-01-13 18:09:04 +03:00
threshold : float = Field (
default = 0.9 ,
2026-02-27 18:55:36 +03:00
title = " Minimum score " ,
description = " Minimum classification score required to accept a bird classification. " ,
2025-01-13 18:09:04 +03:00
gt = 0.0 ,
le = 1.0 ,
)
2025-05-23 17:46:53 +03:00
class CustomClassificationStateCameraConfig ( FrigateBaseModel ) :
2025-10-22 16:36:09 +03:00
crop : list [ float , float , float , float ] = Field (
2026-02-27 18:55:36 +03:00
title = " Classification crop " ,
description = " Crop coordinates to use for running classification on this camera. " ,
2025-05-23 17:46:53 +03:00
)
class CustomClassificationStateConfig ( FrigateBaseModel ) :
cameras : Dict [ str , CustomClassificationStateCameraConfig ] = Field (
2026-02-27 18:55:36 +03:00
title = " Classification cameras " ,
description = " Per-camera crop and settings for running state classification. " ,
2025-05-23 17:46:53 +03:00
)
2025-05-24 19:18:46 +03:00
motion : bool = Field (
default = False ,
2026-02-27 18:55:36 +03:00
title = " Run on motion " ,
description = " If true, run classification when motion is detected within the specified crop. " ,
2025-05-24 19:18:46 +03:00
)
interval : int | None = Field (
default = None ,
2026-02-27 18:55:36 +03:00
title = " Classification interval " ,
description = " Interval (seconds) between periodic classification runs for state classification. " ,
2025-05-24 19:18:46 +03:00
gt = 0 ,
)
2025-05-23 17:46:53 +03:00
class CustomClassificationObjectConfig ( FrigateBaseModel ) :
2026-02-27 18:55:36 +03:00
objects : list [ str ] = Field (
default_factory = list ,
title = " Classify objects " ,
description = " List of object types to run object classification on. " ,
)
2025-07-18 17:28:02 +03:00
classification_type : ObjectClassificationType = Field (
default = ObjectClassificationType . sub_label ,
2026-02-27 18:55:36 +03:00
title = " Classification type " ,
description = " Classification type applied: ' sub_label ' (adds sub_label) or other supported types. " ,
2025-07-18 17:28:02 +03:00
)
2025-05-23 17:46:53 +03:00
class CustomClassificationConfig ( FrigateBaseModel ) :
2026-02-27 18:55:36 +03:00
enabled : bool = Field (
default = True ,
title = " Enable model " ,
description = " Enable or disable the custom classification model. " ,
)
name : str | None = Field (
default = None ,
title = " Model name " ,
description = " Identifier for the custom classification model to use. " ,
)
2025-06-27 17:35:02 +03:00
threshold : float = Field (
2026-02-27 18:55:36 +03:00
default = 0.8 ,
title = " Score threshold " ,
description = " Score threshold used to change the classification state. " ,
2025-06-27 17:35:02 +03:00
)
2025-12-02 17:21:15 +03:00
save_attempts : int | None = Field (
default = None ,
2026-02-27 18:55:36 +03:00
title = " Save attempts " ,
description = " How many classification attempts to save for recent classifications UI. " ,
2025-12-02 17:21:15 +03:00
ge = 0 ,
)
2025-05-23 17:46:53 +03:00
object_config : CustomClassificationObjectConfig | None = Field ( default = None )
state_config : CustomClassificationStateConfig | None = Field ( default = None )
2025-01-13 18:09:04 +03:00
class ClassificationConfig ( FrigateBaseModel ) :
bird : BirdClassificationConfig = Field (
2026-02-27 18:55:36 +03:00
default_factory = BirdClassificationConfig ,
title = " Bird classification config " ,
description = " Settings specific to bird classification models. " ,
2025-01-13 18:09:04 +03:00
)
2025-05-23 17:46:53 +03:00
custom : Dict [ str , CustomClassificationConfig ] = Field (
2026-02-27 18:55:36 +03:00
default = { } ,
title = " Custom Classification Models " ,
description = " Configuration for custom classification models used for objects or state detection. " ,
2025-05-23 17:46:53 +03:00
)
2025-01-13 18:09:04 +03:00
2024-09-28 22:21:42 +03:00
class SemanticSearchConfig ( FrigateBaseModel ) :
2026-02-27 18:55:36 +03:00
enabled : bool = Field (
default = False ,
title = " Enable semantic search " ,
description = " Enable or disable the semantic search feature. " ,
)
2024-09-28 22:21:42 +03:00
reindex : Optional [ bool ] = Field (
2026-02-27 18:55:36 +03:00
default = False ,
title = " Reindex on startup " ,
description = " Trigger a full reindex of historical tracked objects into the embeddings database. " ,
2025-02-26 17:58:25 +03:00
)
model : Optional [ SemanticSearchModelEnum ] = Field (
default = SemanticSearchModelEnum . jinav1 ,
2026-02-27 18:55:36 +03:00
title = " Semantic search model " ,
description = " The embeddings model to use for semantic search (for example ' jinav1 ' ). " ,
2024-09-28 22:21:42 +03:00
)
2024-10-11 01:46:21 +03:00
model_size : str = Field (
2026-02-27 18:55:36 +03:00
default = " small " ,
title = " Model size " ,
description = " Select model size; ' small ' runs on CPU and ' large ' typically requires GPU. " ,
2024-10-11 01:46:21 +03:00
)
2025-08-19 02:43:53 +03:00
device : Optional [ str ] = Field (
default = None ,
2026-02-27 18:55:36 +03:00
title = " Device " ,
2025-08-19 02:43:53 +03:00
description = " This is an override, to target a specific device. See https://onnxruntime.ai/docs/execution-providers/ for more information " ,
)
2024-10-23 18:03:18 +03:00
2025-07-07 17:03:57 +03:00
class TriggerConfig ( FrigateBaseModel ) :
2025-10-03 15:36:14 +03:00
friendly_name : Optional [ str ] = Field (
2026-02-27 18:55:36 +03:00
None ,
title = " Friendly name " ,
description = " Optional friendly name displayed in the UI for this trigger. " ,
)
enabled : bool = Field (
default = True ,
title = " Enable this trigger " ,
description = " Enable or disable this semantic search trigger. " ,
)
type : TriggerType = Field (
default = TriggerType . DESCRIPTION ,
title = " Trigger type " ,
description = " Type of trigger: ' thumbnail ' (match against image) or ' description ' (match against text). " ,
)
data : str = Field (
title = " Trigger content " ,
description = " Text phrase or thumbnail ID to match against tracked objects. " ,
2025-10-03 15:36:14 +03:00
)
2025-07-07 17:03:57 +03:00
threshold : float = Field (
2026-02-27 18:55:36 +03:00
title = " Trigger threshold " ,
description = " Minimum similarity score (0-1) required to activate this trigger. " ,
2025-07-07 17:03:57 +03:00
default = 0.8 ,
gt = 0.0 ,
le = 1.0 ,
)
2025-08-08 15:08:37 +03:00
actions : List [ TriggerAction ] = Field (
2026-02-27 18:55:36 +03:00
default = [ ] ,
title = " Trigger actions " ,
description = " List of actions to execute when trigger matches (notification, sub_label, attribute). " ,
2025-07-07 17:03:57 +03:00
)
model_config = ConfigDict ( extra = " forbid " , protected_namespaces = ( ) )
class CameraSemanticSearchConfig ( FrigateBaseModel ) :
2025-08-08 15:08:37 +03:00
triggers : Dict [ str , TriggerConfig ] = Field (
default = { } ,
2026-02-27 18:55:36 +03:00
title = " Triggers " ,
description = " Actions and matching criteria for camera-specific semantic search triggers. " ,
2025-07-07 17:03:57 +03:00
)
model_config = ConfigDict ( extra = " forbid " , protected_namespaces = ( ) )
2024-10-23 18:03:18 +03:00
class FaceRecognitionConfig ( FrigateBaseModel ) :
2026-02-27 18:55:36 +03:00
enabled : bool = Field (
default = False ,
title = " Enable face recognition " ,
description = " Enable or disable face recognition for all cameras; can be overridden per-camera. " ,
)
2025-03-26 03:59:03 +03:00
model_size : str = Field (
2026-02-27 18:55:36 +03:00
default = " small " ,
title = " Model size " ,
description = " Model size to use for face embeddings (small/large); larger may require GPU. " ,
2025-03-26 03:59:03 +03:00
)
2025-03-26 16:23:01 +03:00
unknown_score : float = Field (
2026-02-27 18:55:36 +03:00
title = " Unknown score threshold " ,
description = " Distance threshold below which a face is considered a potential match (higher = stricter). " ,
2025-01-01 00:56:01 +03:00
default = 0.8 ,
gt = 0.0 ,
le = 1.0 ,
)
2025-03-13 20:22:14 +03:00
detection_threshold : float = Field (
default = 0.7 ,
2026-02-27 18:55:36 +03:00
title = " Detection threshold " ,
description = " Minimum detection confidence required to consider a face detection valid. " ,
2025-03-13 20:22:14 +03:00
gt = 0.0 ,
le = 1.0 ,
)
recognition_threshold : float = Field (
2025-01-01 00:56:01 +03:00
default = 0.9 ,
2026-02-27 18:55:36 +03:00
title = " Recognition threshold " ,
description = " Face embedding distance threshold to consider two faces a match. " ,
2024-11-26 23:41:49 +03:00
gt = 0.0 ,
le = 1.0 ,
2024-10-23 18:03:18 +03:00
)
min_area : int = Field (
2026-02-27 18:55:36 +03:00
default = 750 ,
title = " Minimum face area " ,
description = " Minimum area (pixels) of a detected face box required to attempt recognition. " ,
2024-10-23 18:03:18 +03:00
)
2025-05-18 15:20:59 +03:00
min_faces : int = Field (
default = 1 ,
gt = 0 ,
le = 6 ,
2026-02-27 18:55:36 +03:00
title = " Minimum faces " ,
description = " Minimum number of face recognitions required before applying a recognized sub-label to a person. " ,
2025-05-18 15:20:59 +03:00
)
2025-03-19 18:02:25 +03:00
save_attempts : int = Field (
2025-10-22 16:36:09 +03:00
default = 200 ,
ge = 0 ,
2026-02-27 18:55:36 +03:00
title = " Save attempts " ,
description = " Number of face recognition attempts to retain for recent recognition UI. " ,
2024-12-26 05:52:35 +03:00
)
2025-03-11 22:18:43 +03:00
blur_confidence_filter : bool = Field (
2026-02-27 18:55:36 +03:00
default = True ,
title = " Blur confidence filter " ,
description = " Adjust confidence scores based on image blur to reduce false positives for poor quality faces. " ,
2025-03-11 22:18:43 +03:00
)
2025-08-19 02:43:53 +03:00
device : Optional [ str ] = Field (
default = None ,
2026-02-27 18:55:36 +03:00
title = " Device " ,
2025-08-19 02:43:53 +03:00
description = " This is an override, to target a specific device. See https://onnxruntime.ai/docs/execution-providers/ for more information " ,
)
2024-10-26 20:07:45 +03:00
2025-03-19 18:02:40 +03:00
class CameraFaceRecognitionConfig ( FrigateBaseModel ) :
2026-02-27 18:55:36 +03:00
enabled : bool = Field (
default = False ,
title = " Enable face recognition " ,
description = " Enable or disable face recognition. " ,
)
2025-03-19 18:02:40 +03:00
min_area : int = Field (
2026-02-27 18:55:36 +03:00
default = 750 ,
title = " Minimum face area " ,
description = " Minimum area (pixels) of a detected face box required to attempt recognition. " ,
2025-03-19 18:02:40 +03:00
)
2025-04-24 16:30:10 +03:00
model_config = ConfigDict ( extra = " forbid " , protected_namespaces = ( ) )
2025-03-20 05:52:55 +03:00
2025-03-19 18:02:40 +03:00
2025-09-19 00:12:17 +03:00
class ReplaceRule ( FrigateBaseModel ) :
2026-02-27 18:55:36 +03:00
pattern : str = Field ( . . . , title = " Regex pattern " )
replacement : str = Field ( . . . , title = " Replacement string " )
2025-09-19 00:12:17 +03:00
2024-10-26 20:07:45 +03:00
class LicensePlateRecognitionConfig ( FrigateBaseModel ) :
2026-02-27 18:55:36 +03:00
enabled : bool = Field (
default = False ,
title = " Enable LPR " ,
description = " Enable or disable license plate recognition for all cameras; can be overridden per-camera. " ,
)
2025-04-15 18:40:12 +03:00
model_size : str = Field (
2026-02-27 18:55:36 +03:00
default = " small " ,
title = " Model size " ,
description = " Model size used for text detection/recognition. Most users should use ' small ' . " ,
2025-04-15 18:40:12 +03:00
)
2025-02-15 01:12:36 +03:00
detection_threshold : float = Field (
default = 0.7 ,
2026-02-27 18:55:36 +03:00
title = " Detection threshold " ,
description = " Detection confidence threshold to begin running OCR on a suspected plate. " ,
2025-02-15 01:12:36 +03:00
gt = 0.0 ,
le = 1.0 ,
2024-10-26 20:07:45 +03:00
)
min_area : int = Field (
2025-02-14 02:08:56 +03:00
default = 1000 ,
2026-02-27 18:55:36 +03:00
title = " Minimum plate area " ,
description = " Minimum plate area (pixels) required to attempt recognition. " ,
2025-02-15 01:12:36 +03:00
)
recognition_threshold : float = Field (
default = 0.9 ,
2026-02-27 18:55:36 +03:00
title = " Recognition threshold " ,
description = " Confidence threshold required for recognized plate text to be attached as a sub-label. " ,
2025-02-15 01:12:36 +03:00
gt = 0.0 ,
le = 1.0 ,
2025-02-14 02:08:56 +03:00
)
min_plate_length : int = Field (
default = 4 ,
2026-02-27 18:55:36 +03:00
title = " Min plate length " ,
description = " Minimum number of characters a recognized plate must contain to be considered valid. " ,
2025-02-14 02:08:56 +03:00
)
2025-02-15 01:12:36 +03:00
format : Optional [ str ] = Field (
default = None ,
2026-02-27 18:55:36 +03:00
title = " Plate format regex " ,
description = " Optional regex to validate recognized plate strings against an expected format. " ,
2025-02-15 01:12:36 +03:00
)
2025-02-14 02:08:56 +03:00
match_distance : int = Field (
default = 1 ,
2026-02-27 18:55:36 +03:00
title = " Match distance " ,
description = " Number of character mismatches allowed when comparing detected plates to known plates. " ,
2025-02-15 01:12:36 +03:00
ge = 0 ,
2024-10-26 20:07:45 +03:00
)
known_plates : Optional [ Dict [ str , List [ str ] ] ] = Field (
2026-02-27 18:55:36 +03:00
default = { } ,
title = " Known plates " ,
description = " List of plates or regexes to specially track or alert on. " ,
2024-10-26 20:07:45 +03:00
)
2025-03-28 15:29:11 +03:00
enhancement : int = Field (
default = 0 ,
2026-02-27 18:55:36 +03:00
title = " Enhancement level " ,
description = " Enhancement level (0-10) to apply to plate crops prior to OCR; higher values may not always improve results, levels above 5 may only work with night time plates and should be used with caution. " ,
2025-03-28 15:29:11 +03:00
ge = 0 ,
le = 10 ,
)
debug_save_plates : bool = Field (
default = False ,
2026-02-27 18:55:36 +03:00
title = " Save debug plates " ,
description = " Save plate crop images for debugging LPR performance. " ,
2025-03-28 15:29:11 +03:00
)
2025-08-19 02:43:53 +03:00
device : Optional [ str ] = Field (
default = None ,
2026-02-27 18:55:36 +03:00
title = " Device " ,
2025-08-19 02:43:53 +03:00
description = " This is an override, to target a specific device. See https://onnxruntime.ai/docs/execution-providers/ for more information " ,
)
2025-09-19 00:12:17 +03:00
replace_rules : List [ ReplaceRule ] = Field (
default_factory = list ,
2026-02-27 18:55:36 +03:00
title = " Replacement rules " ,
description = " Regex replacement rules used to normalize detected plate strings before matching. " ,
2025-09-19 00:12:17 +03:00
)
2025-03-19 18:02:40 +03:00
class CameraLicensePlateRecognitionConfig ( FrigateBaseModel ) :
2026-02-27 18:55:36 +03:00
enabled : bool = Field (
default = False ,
title = " Enable LPR " ,
description = " Enable or disable LPR on this camera. " ,
)
2025-03-23 22:30:48 +03:00
expire_time : int = Field (
default = 3 ,
2026-02-27 18:55:36 +03:00
title = " Expire seconds " ,
description = " Time in seconds after which an unseen plate is expired from the tracker (for dedicated LPR cameras only). " ,
2025-03-23 22:30:48 +03:00
gt = 0 ,
)
2025-03-19 18:02:40 +03:00
min_area : int = Field (
default = 1000 ,
2026-02-27 18:55:36 +03:00
title = " Minimum plate area " ,
description = " Minimum plate area (pixels) required to attempt recognition. " ,
2025-03-19 18:02:40 +03:00
)
2025-03-28 15:29:11 +03:00
enhancement : int = Field (
default = 0 ,
2026-02-27 18:55:36 +03:00
title = " Enhancement level " ,
description = " Enhancement level (0-10) to apply to plate crops prior to OCR; higher values may not always improve results, levels above 5 may only work with night time plates and should be used with caution. " ,
2025-03-28 15:29:11 +03:00
ge = 0 ,
le = 10 ,
)
2025-03-20 05:52:55 +03:00
2025-04-24 16:30:10 +03:00
model_config = ConfigDict ( extra = " forbid " , protected_namespaces = ( ) )
2025-10-09 02:06:03 +03:00
class CameraAudioTranscriptionConfig ( FrigateBaseModel ) :
2026-02-27 18:55:36 +03:00
enabled : bool = Field (
default = False ,
title = " Enable transcription " ,
description = " Enable or disable manually triggered audio event transcription. " ,
)
2025-10-09 02:06:03 +03:00
enabled_in_config : Optional [ bool ] = Field (
2026-02-27 18:55:36 +03:00
default = None , title = " Original transcription state "
2025-10-09 02:06:03 +03:00
)
live_enabled : Optional [ bool ] = Field (
2026-02-27 18:55:36 +03:00
default = False ,
title = " Live transcription " ,
description = " Enable streaming live transcription for audio as it is received. " ,
2025-10-09 02:06:03 +03:00
)
model_config = ConfigDict ( extra = " forbid " , protected_namespaces = ( ) )