add enable_cpu_fallback flag with default false

This commit is contained in:
Winston Ametsitsi 2024-03-13 23:07:45 -07:00
parent 85ccd1e8f1
commit 2062cde368
3 changed files with 14 additions and 6 deletions

View File

@ -1329,7 +1329,7 @@ class FrigateConfig(FrigateBaseModel):
)
detector_config.model.compute_model_hash()
if detector_config.type != "cpu":
if detector_config.enable_cpu_fallback and detector_config.type != "cpu":
fallback_config = config.copy(deep=True)
fallback_config.model = ModelConfig()
detector_config.fallback_config = self.generate_detector_config(

View File

@ -139,6 +139,9 @@ class ModelConfig(BaseModel):
class BaseDetectorConfig(BaseModel):
# the type field must be defined in all subclasses
type: str = Field(default="cpu", title="Detector Type")
enable_cpu_fallback: bool = Field(
default=False, title="Fallback to CPU if startup fails"
)
model: ModelConfig = Field(
default=None, title="Detector specific model configuration."
)

View File

@ -103,11 +103,16 @@ def run_detector(
try:
object_detector = LocalObjectDetector(detector_config=detector_config)
except Exception as ex:
logger.error(f"Got exception when initializing detector: {ex}, falling back to CPU detector")
object_detector = LocalObjectDetector(detector_config=detector_config.fallback_config)
using_fallback_detector.value = 1
if detector_config.enable_cpu_fallback:
logger.error(
f"Got exception when initializing detector: {ex}, falling back to CPU detector"
)
object_detector = LocalObjectDetector(
detector_config=detector_config.fallback_config
)
using_fallback_detector.value = 1
else:
raise ex
outputs = {}
for name in out_events.keys():