Fix `deepface` error when no images exist

Accomplished by adding another check for ValueError message
Might be better to warn user if no images exist
This commit is contained in:
slashtechno 2023-12-02 18:21:41 -06:00
parent b5d95ed963
commit de5d6c1ab0
Signed by: slashtechno
GPG Key ID: 8EC1D9D9286C2B17
2 changed files with 9 additions and 2 deletions

View File

@ -60,7 +60,6 @@ def main():
while True: while True:
# Grab a single frame of video # Grab a single frame of video
ret, frame = video_capture.read() ret, frame = video_capture.read()
# Only process every other frame of video to save time
# Resize frame of video to a smaller size for faster recognition processing # Resize frame of video to a smaller size for faster recognition processing
run_frame = cv2.resize(frame, (0, 0), fx=args.run_scale, fy=args.run_scale) run_frame = cv2.resize(frame, (0, 0), fx=args.run_scale, fy=args.run_scale)
# view_frame = cv2.resize(frame, (0, 0), fx=args.view_scale, fy=args.view_scale) # view_frame = cv2.resize(frame, (0, 0), fx=args.view_scale, fy=args.view_scale)

View File

@ -124,13 +124,21 @@ def recognize_face(
model_name="ArcFace", model_name="ArcFace",
detector_backend="opencv", detector_backend="opencv",
) )
except ValueError as e:
except (ValueError) as e:
if ( if (
str(e) str(e)
== "Face could not be detected. Please confirm that the picture is a face photo or consider to set enforce_detection param to False." # noqa: E501 == "Face could not be detected. Please confirm that the picture is a face photo or consider to set enforce_detection param to False." # noqa: E501
): ):
# print("No faces recognized") # For debugging # print("No faces recognized") # For debugging
return None return None
elif (
# Check if the error message contains "Validate .jpg or .png files exist in this path."
"Validate .jpg or .png files exist in this path." in str(e)
):
# If a verbose/silent flag is added, this should be changed to print only if verbose is true
# print("No faces found in database")
return None
else: else:
raise e raise e
# Iteate over the dataframes # Iteate over the dataframes