From 11738110dc2c3eee2302449ff52ed9ff378c1d32 Mon Sep 17 00:00:00 2001 From: Sergey Krashevich Date: Sun, 21 May 2023 16:29:57 +0300 Subject: [PATCH] Add handling for non-existent or empty model file paths (#6525) * Add handling for non-existent or empty model file paths in `compute_model_hash()` method * Remove print() in detector_config.py Co-authored-by: Blake Blackshear --------- Co-authored-by: Blake Blackshear --- frigate/detectors/detector_config.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/frigate/detectors/detector_config.py b/frigate/detectors/detector_config.py index 16ffe5fd4..e949065b4 100644 --- a/frigate/detectors/detector_config.py +++ b/frigate/detectors/detector_config.py @@ -118,11 +118,14 @@ class ModelConfig(BaseModel): } def compute_model_hash(self) -> None: - with open(self.path, "rb") as f: - file_hash = hashlib.md5() - while chunk := f.read(8192): - file_hash.update(chunk) - self._model_hash = file_hash.hexdigest() + if not self.path or not os.path.exists(self.path): + self._model_hash = hashlib.md5(b"unknown").hexdigest() + else: + with open(self.path, "rb") as f: + file_hash = hashlib.md5() + while chunk := f.read(8192): + file_hash.update(chunk) + self._model_hash = file_hash.hexdigest() def create_colormap(self, enabled_labels: set[str]) -> None: """Get a list of colors for enabled labels."""