Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup config validation #11235

Merged
merged 3 commits into from
May 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 12 additions & 15 deletions frigate/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1505,29 +1505,26 @@ def runtime_config(self, plus_api: PlusApi = None) -> FrigateConfig:
for key, detector in config.detectors.items():
adapter = TypeAdapter(DetectorConfig)
model_dict = (
detector if isinstance(detector, dict) else detector.model_dump()
detector
if isinstance(detector, dict)
else detector.model_dump(warnings="none")
)
detector_config: DetectorConfig = adapter.validate_python(model_dict)
if detector_config.model is None:
detector_config.model = config.model
detector_config.model = config.model.model_copy()
else:
model = detector_config.model
schema = ModelConfig.model_json_schema()["properties"]
if (
model.width != schema["width"]["default"]
or model.height != schema["height"]["default"]
or model.labelmap_path is not None
or model.labelmap
or model.input_tensor != schema["input_tensor"]["default"]
or model.input_pixel_format
!= schema["input_pixel_format"]["default"]
):
path = detector_config.model.path
detector_config.model = config.model.model_copy()
detector_config.model.path = path

if "path" not in model_dict or len(model_dict.keys()) > 1:
logger.warning(
"Customizing more than a detector model path is unsupported."
)

merged_model = deep_merge(
detector_config.model.model_dump(exclude_unset=True),
config.model.model_dump(exclude_unset=True),
detector_config.model.model_dump(exclude_unset=True, warnings="none"),
config.model.model_dump(exclude_unset=True, warnings="none"),
)

if "path" not in merged_model:
Expand Down
7 changes: 1 addition & 6 deletions frigate/test/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def test_detector_custom_model_path(self, mock_labels):
},
"edgetpu": {
"type": "edgetpu",
"model": {"path": "/edgetpu_model.tflite", "width": 160},
"model": {"path": "/edgetpu_model.tflite"},
},
"openvino": {
"type": "openvino",
Expand Down Expand Up @@ -112,11 +112,6 @@ def test_detector_custom_model_path(self, mock_labels):
assert runtime_config.detectors["edgetpu"].model.path == "/edgetpu_model.tflite"
assert runtime_config.detectors["openvino"].model.path == "/etc/hosts"

assert runtime_config.model.width == 512
assert runtime_config.detectors["cpu"].model.width == 320
assert runtime_config.detectors["edgetpu"].model.width == 160
assert runtime_config.detectors["openvino"].model.width == 512

def test_invalid_mqtt_config(self):
config = {
"mqtt": {"host": "mqtt", "user": "test"},
Expand Down