From a80d3e8d27efe2ab27c681cb34098486bb49e7de Mon Sep 17 00:00:00 2001 From: Sefik Ilkin Serengil Date: Sun, 1 Sep 2024 09:37:29 +0100 Subject: [PATCH] exception messages updated --- deepface/commons/weight_utils.py | 18 +++++++++--------- tests/test_commons.py | 5 ++++- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/deepface/commons/weight_utils.py b/deepface/commons/weight_utils.py index cbac658..fa44b99 100644 --- a/deepface/commons/weight_utils.py +++ b/deepface/commons/weight_utils.py @@ -49,12 +49,10 @@ def download_weights_if_necessary( gdown.download(source_url, f"{target_file}.{compress_type}", quiet=False) except Exception as err: - exception_msg = ( - f"⛓️‍💥 Exception while downloading {file_name} from {source_url}. " - f"You may consider to download it manually to {target_file}." - ) - logger.error(exception_msg) - raise ValueError(exception_msg) from err + raise ValueError( + f"⛓️‍💥 An exception occurred while downloading {file_name} from {source_url}. " + f"Consider downloading it manually to {target_file}." + ) from err # uncompress downloaded file if compress_type == "zip": @@ -85,8 +83,10 @@ def load_model_weights(model: Sequential, weight_file: str) -> Sequential: model.load_weights(weight_file) except Exception as err: raise ValueError( - f"Exception while loading pre-trained weights from {weight_file}." - "Possible reason is broken file during downloading weights." - "You may consider to delete it manually." + f"An exception occurred while loading the pre-trained weights from {weight_file}." + "This might have happened due to an interruption during the download." + "You may want to delete it and allow DeepFace to download it again during the next run." + "If the issue persists, consider downloading the file directly from the source " + "and copying it to the target folder." ) from err return model diff --git a/tests/test_commons.py b/tests/test_commons.py index 5e8be38..ded1754 100644 --- a/tests/test_commons.py +++ b/tests/test_commons.py @@ -40,7 +40,10 @@ def test_loading_broken_weights(): model.add(Dense(units=10, activation="softmax")) # Output layer with 10 classes # vgg's weights cannot be loaded to this model - with pytest.raises(ValueError, match="Exception while loading pre-trained weights from"): + with pytest.raises( + ValueError, + match="An exception occurred while loading the pre-trained weights from" + ): model = weight_utils.load_model_weights(model=model, weight_file=weight_file) logger.info("✅ test loading broken weight file is done")