mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-08 20:25:26 +03:00
Fix config checks
This commit is contained in:
parent
8921255da3
commit
318fb419f5
@ -1139,7 +1139,7 @@ class FrigateConfig(FrigateBaseModel):
|
|||||||
|
|
||||||
def runtime_config(self, plus_api: PlusApi = None) -> FrigateConfig:
|
def runtime_config(self, plus_api: PlusApi = None) -> FrigateConfig:
|
||||||
"""Merge camera config with globals."""
|
"""Merge camera config with globals."""
|
||||||
config = self.copy(deep=True)
|
config = self.model_copy(deep=True)
|
||||||
|
|
||||||
# MQTT user/password substitutions
|
# MQTT user/password substitutions
|
||||||
if config.mqtt.user or config.mqtt.password:
|
if config.mqtt.user or config.mqtt.password:
|
||||||
@ -1330,7 +1330,7 @@ class FrigateConfig(FrigateBaseModel):
|
|||||||
|
|
||||||
for key, detector in config.detectors.items():
|
for key, detector in config.detectors.items():
|
||||||
adapter = TypeAdapter(DetectorConfig)
|
adapter = TypeAdapter(DetectorConfig)
|
||||||
detector_config: DetectorConfig = adapter.validate_python(detector)
|
detector_config: DetectorConfig = adapter.validate_python(detector.model_dump())
|
||||||
if detector_config.model is None:
|
if detector_config.model is None:
|
||||||
detector_config.model = config.model
|
detector_config.model = config.model
|
||||||
else:
|
else:
|
||||||
|
|||||||
@ -140,7 +140,7 @@ class ModelConfig(BaseModel):
|
|||||||
class BaseDetectorConfig(BaseModel):
|
class BaseDetectorConfig(BaseModel):
|
||||||
# the type field must be defined in all subclasses
|
# the type field must be defined in all subclasses
|
||||||
type: str = Field(default="cpu", title="Detector Type")
|
type: str = Field(default="cpu", title="Detector Type")
|
||||||
model: ModelConfig = Field(
|
model: Optional[ModelConfig] = Field(
|
||||||
default=None, title="Detector specific model configuration."
|
default=None, title="Detector specific model configuration."
|
||||||
)
|
)
|
||||||
model_config = ConfigDict(extra="allow", arbitrary_types_allowed=True)
|
model_config = ConfigDict(extra="allow", arbitrary_types_allowed=True)
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import unittest
|
import unittest
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from pydantic import ValidationError
|
from pydantic import ValidationError
|
||||||
@ -70,7 +71,9 @@ class TestConfig(unittest.TestCase):
|
|||||||
assert runtime_config.detectors["cpu"].type == DetectorTypeEnum.cpu
|
assert runtime_config.detectors["cpu"].type == DetectorTypeEnum.cpu
|
||||||
assert runtime_config.detectors["cpu"].model.width == 320
|
assert runtime_config.detectors["cpu"].model.width == 320
|
||||||
|
|
||||||
def test_detector_custom_model_path(self):
|
@patch("frigate.detectors.detector_config.load_labels")
|
||||||
|
def test_detector_custom_model_path(self, mock_labels):
|
||||||
|
mock_labels.return_value = {}
|
||||||
config = {
|
config = {
|
||||||
"detectors": {
|
"detectors": {
|
||||||
"cpu": {
|
"cpu": {
|
||||||
@ -83,7 +86,6 @@ class TestConfig(unittest.TestCase):
|
|||||||
},
|
},
|
||||||
"openvino": {
|
"openvino": {
|
||||||
"type": "openvino",
|
"type": "openvino",
|
||||||
"model": {"path": "/openvino_model.xml"}
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
# needs to be a file that will exist, doesnt matter what
|
# needs to be a file that will exist, doesnt matter what
|
||||||
@ -111,7 +113,7 @@ class TestConfig(unittest.TestCase):
|
|||||||
assert runtime_config.detectors["openvino"].model.path == "/etc/hosts"
|
assert runtime_config.detectors["openvino"].model.path == "/etc/hosts"
|
||||||
|
|
||||||
assert runtime_config.model.width == 512
|
assert runtime_config.model.width == 512
|
||||||
assert runtime_config.detectors["cpu"].model.width == 512
|
assert runtime_config.detectors["cpu"].model.width == 320
|
||||||
assert runtime_config.detectors["edgetpu"].model.width == 160
|
assert runtime_config.detectors["edgetpu"].model.width == 160
|
||||||
assert runtime_config.detectors["openvino"].model.width == 512
|
assert runtime_config.detectors["openvino"].model.width == 512
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user