Skip to content

Commit

Permalink
Add handling for non-existent or empty model file paths (blakeblacksh…
Browse files Browse the repository at this point in the history
…ear#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 <[email protected]>

---------

Co-authored-by: Blake Blackshear <[email protected]>
  • Loading branch information
skrashevich and blakeblackshear authored May 21, 2023
1 parent 53d63e0 commit 1173811
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions frigate/detectors/detector_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,14 @@ def check_and_load_plus_model(
}

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."""
Expand Down

0 comments on commit 1173811

Please sign in to comment.