From 39a6d2416395163f75d1da207c647c2e792bff20 Mon Sep 17 00:00:00 2001 From: Sefik Ilkin Serengil Date: Sat, 17 Aug 2024 08:10:36 +0100 Subject: [PATCH 1/3] whitespace removed --- deepface/commons/logger.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deepface/commons/logger.py b/deepface/commons/logger.py index c42c950..f494eb8 100644 --- a/deepface/commons/logger.py +++ b/deepface/commons/logger.py @@ -8,7 +8,7 @@ class Logger: A Logger class for logging messages with a specific log level. The class follows the singleton design pattern, ensuring that only one - instance of the Logger is created. The parameters of the first instance + instance of the Logger is created. The parameters of the first instance are preserved across all instances. """ @@ -21,7 +21,7 @@ class Logger: def __init__(self): if not hasattr(self, "_singleton_initialized"): - self._singleton_initialized = True # to prevent multiple initializations + self._singleton_initialized = True # to prevent multiple initializations log_level = os.environ.get("DEEPFACE_LOG_LEVEL", str(logging.INFO)) try: self.log_level = int(log_level) From 52d6873253d103e9a477ad5b634e13eb81e4206a Mon Sep 17 00:00:00 2001 From: Sefik Ilkin Serengil Date: Sat, 17 Aug 2024 08:10:49 +0100 Subject: [PATCH 2/3] exception messages updated --- deepface/modules/verification.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/deepface/modules/verification.py b/deepface/modules/verification.py index a5cc934..b6b1002 100644 --- a/deepface/modules/verification.py +++ b/deepface/modules/verification.py @@ -115,22 +115,21 @@ def verify( } def extract_embeddings_and_facial_areas( - img_path: Union[str, np.ndarray, List[float]], - index: int - ) -> Tuple[List[List[float]], List[dict]]: + 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 image or returns pre-calculated embeddings. Depending on the type of img_path, the function either extracts - facial embeddings from the provided image + facial embeddings from the provided image (via a path or NumPy array) or verifies that the input is a list of pre-calculated embeddings and validates them. Args: - img_path (Union[str, np.ndarray, List[float]]): - - A string representing the file path to an image, - - A NumPy array containing the image data, + img_path (Union[str, np.ndarray, List[float]]): + - A string representing the file path to an image, + - A NumPy array containing the image data, - Or a list of pre-calculated embedding values (of type `float`). index (int): An index value used in error messages and logging to identify the number of the image. @@ -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] From e9d96a789d6b2e31835133779d4a5cc424b9c723 Mon Sep 17 00:00:00 2001 From: Sefik Ilkin Serengil Date: Sat, 17 Aug 2024 08:11:44 +0100 Subject: [PATCH 3/3] these things covered - expected exception messages updated - nested embedding input is not supported, this is checked --- tests/test_verify.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/tests/test_verify.py b/tests/test_verify.py index 0277507..c1a80e4 100644 --- a/tests/test_verify.py +++ b/tests/test_verify.py @@ -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 @@ -171,4 +171,18 @@ def test_verify_for_broken_embeddings(): 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_embeddings) - logger.info("✅ test verify for broken embeddings content is done") \ No newline at end of file + 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)