Merge pull request #1310 from serengil/feat-task-1708-exception-messages-refactored-for-1339

Feat task 1708 exception messages refactored for 1339
This commit is contained in:
Sefik Ilkin Serengil 2024-08-17 08:26:54 +01:00 committed by GitHub
commit f2c2bb27e4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 26 additions and 13 deletions

View File

@ -115,8 +115,7 @@ def verify(
}
def extract_embeddings_and_facial_areas(
img_path: Union[str, np.ndarray, List[float]],
index: int
img_path: Union[str, np.ndarray, List[float]], index: int
) -> Tuple[List[List[float]], List[dict]]:
"""
Extracts facial embeddings and corresponding facial areas from an
@ -150,7 +149,7 @@ def verify(
if silent is False:
logger.warn(
"You passed 1st image as pre-calculated embeddings."
f"You passed {index}-th image as pre-calculated embeddings."
"Please ensure that embeddings have been calculated"
f" for the {model_name} model."
)
@ -158,7 +157,7 @@ def verify(
if len(img_path) != dims:
raise ValueError(
f"embeddings of {model_name} should have {dims} dimensions,"
f" but it has {len(img_path)} dimensions input"
f" but {index}-th image has {len(img_path)} dimensions input"
)
img_embeddings = [img_path]

View File

@ -153,7 +153,7 @@ def test_verify_with_precalculated_embeddings_for_incorrect_model():
with pytest.raises(
ValueError,
match="embeddings of Facenet should have 128 dimensions, but it has 4096 dimensions input",
match="embeddings of Facenet should have 128 dimensions, but 1-th image has 4096 dimensions input",
):
_ = DeepFace.verify(
img1_path=img1_embedding, img2_path=img2_embedding, model_name="Facenet", silent=True
@ -172,3 +172,17 @@ def test_verify_for_broken_embeddings():
):
_ = DeepFace.verify(img1_path=img1_embeddings, img2_path=img2_embeddings)
logger.info("✅ test verify for broken embeddings content is done")
def test_verify_for_nested_embeddings():
"""
batch embeddings not supported
"""
img1_embeddings = [[1, 2, 3], [4, 5, 6]]
img2_path = "dataset/img1.jpg"
with pytest.raises(
ValueError,
match="When passing img1_path as a list, ensure that all its items are of type float",
):
_ = DeepFace.verify(img1_path=img1_embeddings, img2_path=img2_path)