Skip to content

Commit f2c2bb2

Browse files
authored
Merge pull request #1310 from serengil/feat-task-1708-exception-messages-refactored-for-1339
Feat task 1708 exception messages refactored for 1339
2 parents 9768abc + e9d96a7 commit f2c2bb2

File tree

3 files changed

+26
-13
lines changed

3 files changed

+26
-13
lines changed

deepface/commons/logger.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class Logger:
88
A Logger class for logging messages with a specific log level.
99
1010
The class follows the singleton design pattern, ensuring that only one
11-
instance of the Logger is created. The parameters of the first instance
11+
instance of the Logger is created. The parameters of the first instance
1212
are preserved across all instances.
1313
"""
1414

@@ -21,7 +21,7 @@ def __new__(cls):
2121

2222
def __init__(self):
2323
if not hasattr(self, "_singleton_initialized"):
24-
self._singleton_initialized = True # to prevent multiple initializations
24+
self._singleton_initialized = True # to prevent multiple initializations
2525
log_level = os.environ.get("DEEPFACE_LOG_LEVEL", str(logging.INFO))
2626
try:
2727
self.log_level = int(log_level)

deepface/modules/verification.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,22 +115,21 @@ def verify(
115115
}
116116

117117
def extract_embeddings_and_facial_areas(
118-
img_path: Union[str, np.ndarray, List[float]],
119-
index: int
120-
) -> Tuple[List[List[float]], List[dict]]:
118+
img_path: Union[str, np.ndarray, List[float]], index: int
119+
) -> Tuple[List[List[float]], List[dict]]:
121120
"""
122121
Extracts facial embeddings and corresponding facial areas from an
123122
image or returns pre-calculated embeddings.
124123
125124
Depending on the type of img_path, the function either extracts
126-
facial embeddings from the provided image
125+
facial embeddings from the provided image
127126
(via a path or NumPy array) or verifies that the input is a list of
128127
pre-calculated embeddings and validates them.
129128
130129
Args:
131-
img_path (Union[str, np.ndarray, List[float]]):
132-
- A string representing the file path to an image,
133-
- A NumPy array containing the image data,
130+
img_path (Union[str, np.ndarray, List[float]]):
131+
- A string representing the file path to an image,
132+
- A NumPy array containing the image data,
134133
- Or a list of pre-calculated embedding values (of type `float`).
135134
index (int): An index value used in error messages and logging
136135
to identify the number of the image.
@@ -150,15 +149,15 @@ def extract_embeddings_and_facial_areas(
150149

151150
if silent is False:
152151
logger.warn(
153-
"You passed 1st image as pre-calculated embeddings."
152+
f"You passed {index}-th image as pre-calculated embeddings."
154153
"Please ensure that embeddings have been calculated"
155154
f" for the {model_name} model."
156155
)
157156

158157
if len(img_path) != dims:
159158
raise ValueError(
160159
f"embeddings of {model_name} should have {dims} dimensions,"
161-
f" but it has {len(img_path)} dimensions input"
160+
f" but {index}-th image has {len(img_path)} dimensions input"
162161
)
163162

164163
img_embeddings = [img_path]

tests/test_verify.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def test_verify_with_precalculated_embeddings_for_incorrect_model():
153153

154154
with pytest.raises(
155155
ValueError,
156-
match="embeddings of Facenet should have 128 dimensions, but it has 4096 dimensions input",
156+
match="embeddings of Facenet should have 128 dimensions, but 1-th image has 4096 dimensions input",
157157
):
158158
_ = DeepFace.verify(
159159
img1_path=img1_embedding, img2_path=img2_embedding, model_name="Facenet", silent=True
@@ -171,4 +171,18 @@ def test_verify_for_broken_embeddings():
171171
match="When passing img1_path as a list, ensure that all its items are of type float.",
172172
):
173173
_ = DeepFace.verify(img1_path=img1_embeddings, img2_path=img2_embeddings)
174-
logger.info("✅ test verify for broken embeddings content is done")
174+
logger.info("✅ test verify for broken embeddings content is done")
175+
176+
177+
def test_verify_for_nested_embeddings():
178+
"""
179+
batch embeddings not supported
180+
"""
181+
img1_embeddings = [[1, 2, 3], [4, 5, 6]]
182+
img2_path = "dataset/img1.jpg"
183+
184+
with pytest.raises(
185+
ValueError,
186+
match="When passing img1_path as a list, ensure that all its items are of type float",
187+
):
188+
_ = DeepFace.verify(img1_path=img1_embeddings, img2_path=img2_path)

0 commit comments

Comments
 (0)