mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-03 17:55:21 +03:00
simplify config changes further
This commit is contained in:
parent
b7fd53ecc7
commit
f65bdd29bc
@ -3,7 +3,7 @@ from statistics import mean
|
|||||||
import multiprocessing as mp
|
import multiprocessing as mp
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import datetime
|
import datetime
|
||||||
from frigate.detectors import DetectorTypeEnum
|
from frigate.config import DetectorTypeEnum
|
||||||
from frigate.object_detection import (
|
from frigate.object_detection import (
|
||||||
LocalObjectDetector,
|
LocalObjectDetector,
|
||||||
ObjectDetectProcess,
|
ObjectDetectProcess,
|
||||||
|
|||||||
@ -24,6 +24,7 @@ from frigate.util import (
|
|||||||
get_ffmpeg_arg_list,
|
get_ffmpeg_arg_list,
|
||||||
escape_special_characters,
|
escape_special_characters,
|
||||||
load_config_with_no_duplicates,
|
load_config_with_no_duplicates,
|
||||||
|
load_labels,
|
||||||
)
|
)
|
||||||
from frigate.ffmpeg_presets import (
|
from frigate.ffmpeg_presets import (
|
||||||
parse_preset_hardware_acceleration,
|
parse_preset_hardware_acceleration,
|
||||||
@ -31,8 +32,8 @@ from frigate.ffmpeg_presets import (
|
|||||||
parse_preset_output_record,
|
parse_preset_output_record,
|
||||||
parse_preset_output_rtmp,
|
parse_preset_output_rtmp,
|
||||||
)
|
)
|
||||||
|
from frigate.detectors import DetectorTypeEnum
|
||||||
from frigate.version import VERSION
|
from frigate.version import VERSION
|
||||||
from frigate.detectors.config import ModelConfig, DetectorConfig
|
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@ -714,6 +715,70 @@ class DatabaseConfig(FrigateBaseModel):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class PixelFormatEnum(str, Enum):
|
||||||
|
rgb = "rgb"
|
||||||
|
bgr = "bgr"
|
||||||
|
yuv = "yuv"
|
||||||
|
|
||||||
|
|
||||||
|
class InputTensorEnum(str, Enum):
|
||||||
|
nchw = "nchw"
|
||||||
|
nhwc = "nhwc"
|
||||||
|
|
||||||
|
|
||||||
|
class ModelConfig(FrigateBaseModel):
|
||||||
|
path: Optional[str] = Field(title="Custom Object detection model path.")
|
||||||
|
labelmap_path: Optional[str] = Field(title="Label map for custom object detector.")
|
||||||
|
width: int = Field(default=320, title="Object detection model input width.")
|
||||||
|
height: int = Field(default=320, title="Object detection model input height.")
|
||||||
|
labelmap: Dict[int, str] = Field(
|
||||||
|
default_factory=dict, title="Labelmap customization."
|
||||||
|
)
|
||||||
|
input_tensor: InputTensorEnum = Field(
|
||||||
|
default=InputTensorEnum.nhwc, title="Model Input Tensor Shape"
|
||||||
|
)
|
||||||
|
input_pixel_format: PixelFormatEnum = Field(
|
||||||
|
default=PixelFormatEnum.rgb, title="Model Input Pixel Color Format"
|
||||||
|
)
|
||||||
|
_merged_labelmap: Optional[Dict[int, str]] = PrivateAttr()
|
||||||
|
_colormap: Dict[int, Tuple[int, int, int]] = PrivateAttr()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def merged_labelmap(self) -> Dict[int, str]:
|
||||||
|
return self._merged_labelmap
|
||||||
|
|
||||||
|
@property
|
||||||
|
def colormap(self) -> Dict[int, Tuple[int, int, int]]:
|
||||||
|
return self._colormap
|
||||||
|
|
||||||
|
def __init__(self, **config):
|
||||||
|
super().__init__(**config)
|
||||||
|
|
||||||
|
self._merged_labelmap = {
|
||||||
|
**load_labels(config.get("labelmap_path", "/labelmap.txt")),
|
||||||
|
**config.get("labelmap", {}),
|
||||||
|
}
|
||||||
|
|
||||||
|
cmap = plt.cm.get_cmap("tab10", len(self._merged_labelmap.keys()))
|
||||||
|
|
||||||
|
self._colormap = {}
|
||||||
|
for key, val in self._merged_labelmap.items():
|
||||||
|
self._colormap[val] = tuple(int(round(255 * c)) for c in cmap(key)[:3])
|
||||||
|
|
||||||
|
|
||||||
|
class DetectorConfig(BaseModel):
|
||||||
|
type: str = Field(default=DetectorTypeEnum.cpu, title="Detector Type")
|
||||||
|
device: Optional[str] = Field(default="usb", title="Device Type")
|
||||||
|
num_threads: Optional[int] = Field(default=3, title="Number of detection threads")
|
||||||
|
model: ModelConfig = Field(
|
||||||
|
default=None, title="Detector specific model configuration."
|
||||||
|
)
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
extra = Extra.allow
|
||||||
|
arbitrary_types_allowed = True
|
||||||
|
|
||||||
|
|
||||||
class LogLevelEnum(str, Enum):
|
class LogLevelEnum(str, Enum):
|
||||||
debug = "debug"
|
debug = "debug"
|
||||||
info = "info"
|
info = "info"
|
||||||
@ -825,10 +890,10 @@ class FrigateConfig(FrigateBaseModel):
|
|||||||
)
|
)
|
||||||
ui: UIConfig = Field(default_factory=UIConfig, title="UI configuration.")
|
ui: UIConfig = Field(default_factory=UIConfig, title="UI configuration.")
|
||||||
model: ModelConfig = Field(
|
model: ModelConfig = Field(
|
||||||
default_factory=ModelConfig, title="Default detection model configuration."
|
default_factory=ModelConfig, title="Detection model configuration."
|
||||||
)
|
)
|
||||||
detectors: Dict[str, DetectorConfig] = Field(
|
detectors: Dict[str, DetectorConfig] = Field(
|
||||||
default=DEFAULT_DETECTORS,
|
default={name: DetectorConfig(**d) for name, d in DEFAULT_DETECTORS.items()},
|
||||||
title="Detector hardware configuration.",
|
title="Detector hardware configuration.",
|
||||||
)
|
)
|
||||||
logger: LoggerConfig = Field(
|
logger: LoggerConfig = Field(
|
||||||
|
|||||||
@ -2,13 +2,12 @@ import logging
|
|||||||
|
|
||||||
from .detection_api import DetectionApi
|
from .detection_api import DetectionApi
|
||||||
from .detector_types import DetectorTypeEnum, api_types
|
from .detector_types import DetectorTypeEnum, api_types
|
||||||
from .config import ModelConfig, DetectorConfig
|
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def create_detector(detector_config: DetectorConfig):
|
def create_detector(detector_config):
|
||||||
if detector_config.type == DetectorTypeEnum.cpu:
|
if detector_config.type == DetectorTypeEnum.cpu:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"CPU detectors are not recommended and should only be used for testing or for trial purposes."
|
"CPU detectors are not recommended and should only be used for testing or for trial purposes."
|
||||||
|
|||||||
@ -1,73 +0,0 @@
|
|||||||
import logging
|
|
||||||
from typing import Dict, List, Optional, Tuple, Union, Literal
|
|
||||||
from typing_extensions import Annotated
|
|
||||||
|
|
||||||
import matplotlib.pyplot as plt
|
|
||||||
from pydantic import BaseModel, Extra, Field, validator, parse_obj_as
|
|
||||||
from pydantic.fields import PrivateAttr
|
|
||||||
|
|
||||||
from frigate.enums import InputTensorEnum, PixelFormatEnum
|
|
||||||
from frigate.util import load_labels
|
|
||||||
from .detector_types import DetectorTypeEnum
|
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
class ModelConfig(BaseModel):
|
|
||||||
path: Optional[str] = Field(title="Custom Object detection model path.")
|
|
||||||
labelmap_path: Optional[str] = Field(title="Label map for custom object detector.")
|
|
||||||
width: int = Field(default=320, title="Object detection model input width.")
|
|
||||||
height: int = Field(default=320, title="Object detection model input height.")
|
|
||||||
labelmap: Dict[int, str] = Field(
|
|
||||||
default_factory=dict, title="Labelmap customization."
|
|
||||||
)
|
|
||||||
input_tensor: InputTensorEnum = Field(
|
|
||||||
default=InputTensorEnum.nhwc, title="Model Input Tensor Shape"
|
|
||||||
)
|
|
||||||
input_pixel_format: PixelFormatEnum = Field(
|
|
||||||
default=PixelFormatEnum.rgb, title="Model Input Pixel Color Format"
|
|
||||||
)
|
|
||||||
_merged_labelmap: Optional[Dict[int, str]] = PrivateAttr()
|
|
||||||
_colormap: Dict[int, Tuple[int, int, int]] = PrivateAttr()
|
|
||||||
|
|
||||||
@property
|
|
||||||
def merged_labelmap(self) -> Dict[int, str]:
|
|
||||||
return self._merged_labelmap
|
|
||||||
|
|
||||||
@property
|
|
||||||
def colormap(self) -> Dict[int, Tuple[int, int, int]]:
|
|
||||||
return self._colormap
|
|
||||||
|
|
||||||
def __init__(self, **config):
|
|
||||||
super().__init__(**config)
|
|
||||||
|
|
||||||
self._merged_labelmap = {
|
|
||||||
**load_labels(config.get("labelmap_path", "/labelmap.txt")),
|
|
||||||
**config.get("labelmap", {}),
|
|
||||||
}
|
|
||||||
|
|
||||||
cmap = plt.cm.get_cmap("tab10", len(self._merged_labelmap.keys()))
|
|
||||||
|
|
||||||
self._colormap = {}
|
|
||||||
for key, val in self._merged_labelmap.items():
|
|
||||||
self._colormap[val] = tuple(int(round(255 * c)) for c in cmap(key)[:3])
|
|
||||||
|
|
||||||
class Config:
|
|
||||||
extra = Extra.forbid
|
|
||||||
|
|
||||||
|
|
||||||
class DetectorConfig(BaseModel):
|
|
||||||
type: str = Field(default=DetectorTypeEnum.cpu, title="Detector Type")
|
|
||||||
model: ModelConfig = Field(
|
|
||||||
default=None, title="Detector specific model configuration."
|
|
||||||
)
|
|
||||||
num_threads: Optional[int] = Field(default=3, title="Number of detection threads")
|
|
||||||
device: Optional[str] = Field(default="usb", title="Device Type")
|
|
||||||
|
|
||||||
class Config:
|
|
||||||
extra = Extra.allow
|
|
||||||
arbitrary_types_allowed = True
|
|
||||||
|
|
||||||
|
|
||||||
DEFAULT_DETECTORS = parse_obj_as(Dict[str, DetectorConfig], {"cpu": {"type": "cpu"}})
|
|
||||||
@ -1,12 +0,0 @@
|
|||||||
from enum import Enum
|
|
||||||
|
|
||||||
|
|
||||||
class PixelFormatEnum(str, Enum):
|
|
||||||
rgb = "rgb"
|
|
||||||
bgr = "bgr"
|
|
||||||
yuv = "yuv"
|
|
||||||
|
|
||||||
|
|
||||||
class InputTensorEnum(str, Enum):
|
|
||||||
nchw = "nchw"
|
|
||||||
nhwc = "nhwc"
|
|
||||||
@ -10,7 +10,7 @@ from abc import ABC, abstractmethod
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
from setproctitle import setproctitle
|
from setproctitle import setproctitle
|
||||||
|
|
||||||
from frigate.enums import InputTensorEnum
|
from frigate.config import InputTensorEnum
|
||||||
from frigate.detectors import create_detector
|
from frigate.detectors import create_detector
|
||||||
|
|
||||||
from frigate.util import EventsPerSecond, SharedMemoryFrameManager, listen, load_labels
|
from frigate.util import EventsPerSecond, SharedMemoryFrameManager, listen, load_labels
|
||||||
|
|||||||
@ -3,9 +3,8 @@ from unittest.mock import Mock, patch
|
|||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
from frigate.enums import InputTensorEnum
|
from frigate.config import DetectorConfig, InputTensorEnum, ModelConfig
|
||||||
from frigate.detectors import DetectorTypeEnum
|
from frigate.detectors import DetectorTypeEnum
|
||||||
from frigate.detectors.config import DetectorConfig, ModelConfig
|
|
||||||
import frigate.detectors as detectors
|
import frigate.detectors as detectors
|
||||||
import frigate.object_detection
|
import frigate.object_detection
|
||||||
|
|
||||||
|
|||||||
@ -14,9 +14,8 @@ import numpy as np
|
|||||||
import cv2
|
import cv2
|
||||||
from setproctitle import setproctitle
|
from setproctitle import setproctitle
|
||||||
|
|
||||||
from frigate.config import CameraConfig, DetectConfig
|
from frigate.config import CameraConfig, DetectConfig, PixelFormatEnum
|
||||||
from frigate.const import CACHE_DIR
|
from frigate.const import CACHE_DIR
|
||||||
from frigate.enums import PixelFormatEnum
|
|
||||||
from frigate.object_detection import RemoteObjectDetector
|
from frigate.object_detection import RemoteObjectDetector
|
||||||
from frigate.log import LogPipe
|
from frigate.log import LogPipe
|
||||||
from frigate.motion import MotionDetector
|
from frigate.motion import MotionDetector
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user