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 <blakeb@blakeshome.com>

---------

Co-authored-by: Blake Blackshear <blakeb@blakeshome.com>
This commit is contained in:
Sergey Krashevich 2023-05-21 16:29:57 +03:00 committed by GitHub
parent 53d63e0f75
commit 11738110dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -118,11 +118,14 @@ class ModelConfig(BaseModel):
} }
def compute_model_hash(self) -> None: def compute_model_hash(self) -> None:
with open(self.path, "rb") as f: if not self.path or not os.path.exists(self.path):
file_hash = hashlib.md5() self._model_hash = hashlib.md5(b"unknown").hexdigest()
while chunk := f.read(8192): else:
file_hash.update(chunk) with open(self.path, "rb") as f:
self._model_hash = file_hash.hexdigest() 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: def create_colormap(self, enabled_labels: set[str]) -> None:
"""Get a list of colors for enabled labels.""" """Get a list of colors for enabled labels."""