Skip to content

Commit

Permalink
resolving issue 1098
Browse files Browse the repository at this point in the history
  • Loading branch information
serengil committed Mar 11, 2024
1 parent ec4c3cd commit 820ba59
Showing 1 changed file with 35 additions and 30 deletions.
65 changes: 35 additions & 30 deletions deepface/modules/verification.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def verify(
model: FacialRecognition = modeling.build_model(model_name)
dims = model.output_shape

# extract faces from img1
if isinstance(img1_path, list):
# given image is already pre-calculated embedding
if not all(isinstance(dim, float) for dim in img1_path):
Expand All @@ -115,16 +116,20 @@ def verify(
img1_embeddings = [img1_path]
img1_facial_areas = [None]
else:
img1_embeddings, img1_facial_areas = __extract_faces_and_embeddings(
img_path=img1_path,
model_name=model_name,
detector_backend=detector_backend,
enforce_detection=enforce_detection,
align=align,
expand_percentage=expand_percentage,
normalization=normalization,
)
try:
img1_embeddings, img1_facial_areas = __extract_faces_and_embeddings(
img_path=img1_path,
model_name=model_name,
detector_backend=detector_backend,
enforce_detection=enforce_detection,
align=align,
expand_percentage=expand_percentage,
normalization=normalization,
)
except ValueError as err:
raise ValueError("Exception while processing img1_path") from err

# extract faces from img2
if isinstance(img2_path, list):
# given image is already pre-calculated embedding
if not all(isinstance(dim, float) for dim in img2_path):
Expand All @@ -147,15 +152,18 @@ def verify(
img2_embeddings = [img2_path]
img2_facial_areas = [None]
else:
img2_embeddings, img2_facial_areas = __extract_faces_and_embeddings(
img_path=img2_path,
model_name=model_name,
detector_backend=detector_backend,
enforce_detection=enforce_detection,
align=align,
expand_percentage=expand_percentage,
normalization=normalization,
)
try:
img2_embeddings, img2_facial_areas = __extract_faces_and_embeddings(
img_path=img2_path,
model_name=model_name,
detector_backend=detector_backend,
enforce_detection=enforce_detection,
align=align,
expand_percentage=expand_percentage,
normalization=normalization,
)
except ValueError as err:
raise ValueError("Exception while processing img2_path") from err

no_facial_area = {
"x": None,
Expand Down Expand Up @@ -218,18 +226,15 @@ def __extract_faces_and_embeddings(
model: FacialRecognition = modeling.build_model(model_name)
target_size = model.input_shape

try:
img_objs = detection.extract_faces(
img_path=img_path,
target_size=target_size,
detector_backend=detector_backend,
grayscale=False,
enforce_detection=enforce_detection,
align=align,
expand_percentage=expand_percentage,
)
except ValueError as err:
raise ValueError("Exception while processing img1_path") from err
img_objs = detection.extract_faces(
img_path=img_path,
target_size=target_size,
detector_backend=detector_backend,
grayscale=False,
enforce_detection=enforce_detection,
align=align,
expand_percentage=expand_percentage,
)

# find embeddings for each face
for img_obj in img_objs:
Expand Down

0 comments on commit 820ba59

Please sign in to comment.