Skip to content

Commit

Permalink
exception messages updated
Browse files Browse the repository at this point in the history
  • Loading branch information
serengil committed Sep 1, 2024
1 parent 2feb703 commit a80d3e8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
18 changes: 9 additions & 9 deletions deepface/commons/weight_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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
5 changes: 4 additions & 1 deletion tests/test_commons.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

0 comments on commit a80d3e8

Please sign in to comment.