mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-18 09:04:28 +03:00
Simplify model config
This commit is contained in:
parent
c2e3938ec0
commit
3ded902aa6
@ -594,35 +594,29 @@ class FrigateConfig(FrigateBaseModel):
|
|||||||
if isinstance(detector, dict)
|
if isinstance(detector, dict)
|
||||||
else detector.model_dump(warnings="none")
|
else detector.model_dump(warnings="none")
|
||||||
)
|
)
|
||||||
detector_config: DetectorConfig = adapter.validate_python(model_dict)
|
detector_config: BaseDetectorConfig = adapter.validate_python(model_dict)
|
||||||
if detector_config.model is None:
|
|
||||||
detector_config.model = self.model.model_copy()
|
|
||||||
else:
|
|
||||||
path = detector_config.model.path
|
|
||||||
detector_config.model = self.model.model_copy()
|
|
||||||
detector_config.model.path = path
|
|
||||||
|
|
||||||
if "path" not in model_dict or len(model_dict.keys()) > 1:
|
# users should not set model themselves
|
||||||
logger.warning(
|
if detector_config.model:
|
||||||
"Customizing more than a detector model path is unsupported."
|
detector_config.model = None
|
||||||
)
|
|
||||||
|
|
||||||
merged_model = deep_merge(
|
model_config = self.model.model_dump(exclude_unset=True, warnings="none")
|
||||||
detector_config.model.model_dump(exclude_unset=True, warnings="none"),
|
|
||||||
self.model.model_dump(exclude_unset=True, warnings="none"),
|
|
||||||
)
|
|
||||||
|
|
||||||
if "path" not in merged_model:
|
if detector_config.model_path:
|
||||||
|
model_config["path"] = detector_config.model_path
|
||||||
|
|
||||||
|
if "path" not in model_config:
|
||||||
if detector_config.type == "cpu":
|
if detector_config.type == "cpu":
|
||||||
merged_model["path"] = "/cpu_model.tflite"
|
model_config["path"] = "/cpu_model.tflite"
|
||||||
elif detector_config.type == "edgetpu":
|
elif detector_config.type == "edgetpu":
|
||||||
merged_model["path"] = "/edgetpu_model.tflite"
|
model_config["path"] = "/edgetpu_model.tflite"
|
||||||
|
|
||||||
detector_config.model = ModelConfig.model_validate(merged_model)
|
model = ModelConfig.model_validate(model_config)
|
||||||
detector_config.model.check_and_load_plus_model(
|
model.check_and_load_plus_model(
|
||||||
self.plus_api, detector_config.type
|
self.plus_api, detector_config.type
|
||||||
)
|
)
|
||||||
detector_config.model.compute_model_hash()
|
model.compute_model_hash()
|
||||||
|
detector_config.model = model
|
||||||
self.detectors[key] = detector_config
|
self.detectors[key] = detector_config
|
||||||
|
|
||||||
return self
|
return self
|
||||||
|
|||||||
@ -194,6 +194,9 @@ class BaseDetectorConfig(BaseModel):
|
|||||||
model: Optional[ModelConfig] = Field(
|
model: Optional[ModelConfig] = Field(
|
||||||
default=None, title="Detector specific model configuration."
|
default=None, title="Detector specific model configuration."
|
||||||
)
|
)
|
||||||
|
model_path: Optional[str] = Field(
|
||||||
|
default=None, title="Detector specific model path."
|
||||||
|
)
|
||||||
model_config = ConfigDict(
|
model_config = ConfigDict(
|
||||||
extra="allow", arbitrary_types_allowed=True, protected_namespaces=()
|
extra="allow", arbitrary_types_allowed=True, protected_namespaces=()
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user