resolving issue 1098

This commit is contained in:
Sefik Ilkin Serengil 2024-03-11 18:39:00 +00:00
parent ec4c3cd17c
commit 820ba5946b

View File

@ -93,6 +93,7 @@ def verify(
model: FacialRecognition = modeling.build_model(model_name) model: FacialRecognition = modeling.build_model(model_name)
dims = model.output_shape dims = model.output_shape
# extract faces from img1
if isinstance(img1_path, list): if isinstance(img1_path, list):
# given image is already pre-calculated embedding # given image is already pre-calculated embedding
if not all(isinstance(dim, float) for dim in img1_path): if not all(isinstance(dim, float) for dim in img1_path):
@ -115,6 +116,7 @@ def verify(
img1_embeddings = [img1_path] img1_embeddings = [img1_path]
img1_facial_areas = [None] img1_facial_areas = [None]
else: else:
try:
img1_embeddings, img1_facial_areas = __extract_faces_and_embeddings( img1_embeddings, img1_facial_areas = __extract_faces_and_embeddings(
img_path=img1_path, img_path=img1_path,
model_name=model_name, model_name=model_name,
@ -124,7 +126,10 @@ def verify(
expand_percentage=expand_percentage, expand_percentage=expand_percentage,
normalization=normalization, normalization=normalization,
) )
except ValueError as err:
raise ValueError("Exception while processing img1_path") from err
# extract faces from img2
if isinstance(img2_path, list): if isinstance(img2_path, list):
# given image is already pre-calculated embedding # given image is already pre-calculated embedding
if not all(isinstance(dim, float) for dim in img2_path): if not all(isinstance(dim, float) for dim in img2_path):
@ -147,6 +152,7 @@ def verify(
img2_embeddings = [img2_path] img2_embeddings = [img2_path]
img2_facial_areas = [None] img2_facial_areas = [None]
else: else:
try:
img2_embeddings, img2_facial_areas = __extract_faces_and_embeddings( img2_embeddings, img2_facial_areas = __extract_faces_and_embeddings(
img_path=img2_path, img_path=img2_path,
model_name=model_name, model_name=model_name,
@ -156,6 +162,8 @@ def verify(
expand_percentage=expand_percentage, expand_percentage=expand_percentage,
normalization=normalization, normalization=normalization,
) )
except ValueError as err:
raise ValueError("Exception while processing img2_path") from err
no_facial_area = { no_facial_area = {
"x": None, "x": None,
@ -218,7 +226,6 @@ def __extract_faces_and_embeddings(
model: FacialRecognition = modeling.build_model(model_name) model: FacialRecognition = modeling.build_model(model_name)
target_size = model.input_shape target_size = model.input_shape
try:
img_objs = detection.extract_faces( img_objs = detection.extract_faces(
img_path=img_path, img_path=img_path,
target_size=target_size, target_size=target_size,
@ -228,8 +235,6 @@ def __extract_faces_and_embeddings(
align=align, align=align,
expand_percentage=expand_percentage, expand_percentage=expand_percentage,
) )
except ValueError as err:
raise ValueError("Exception while processing img1_path") from err
# find embeddings for each face # find embeddings for each face
for img_obj in img_objs: for img_obj in img_objs: