Fixed model cache loader
Some checks reported errors
continuous-integration/drone/push Build was killed

This commit is contained in:
Pünkösd Marcell 2021-08-04 15:50:36 +02:00
parent be361a7c18
commit d17ab9d401

View File

@ -78,14 +78,25 @@ class ClassifierCache:
model_details = r.json() model_details = r.json()
if (not self._current_model_details) or (self._current_model_details['id'] != model_details['id']): if ('id' not in model_details) or not model_details['id']:
logging.info(f"Model needs to be loaded (local: {self._current_model_details['id']} model service default: {model_details['id']})") raise KeyError("Model info is invalid!")
current_model_id = None
if self._current_model_details:
current_model_id = self._current_model_details['id']
if current_model_id != model_details['id']:
logging.info(
f"Model needs to be loaded (local: {current_model_id}; modelsvc def: {model_details['id']})"
)
# If the currently loaded model is not the default... then load it # If the currently loaded model is not the default... then load it
self._cleanup() # delete/unload everything self._cleanup() # delete/unload everything
self._download_and_load_model(model_details['files']['model'], model_details['files']['weights']) self._download_and_load_model(model_details['files']['model'], model_details['files']['weights'])
self._current_model_details = model_details self._current_model_details = model_details
else: else:
logging.debug(f"Currently loaded model seems up to date ({self._current_model_details['id']} == {model_details['id']})") logging.debug(
f"Currently loaded model seems up to date ({current_model_id} == {model_details['id']})"
)
else: else:
logging.debug("Cache is still valid. Not fetching model info") logging.debug("Cache is still valid. Not fetching model info")