From de5d6c1ab0ea4f769759e84053b3de11277544b6 Mon Sep 17 00:00:00 2001 From: slashtechno <77907286+slashtechno@users.noreply.github.com> Date: Sat, 2 Dec 2023 18:21:41 -0600 Subject: [PATCH] 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 --- wyzely_detect/__main__.py | 1 - wyzely_detect/utils/utils.py | 10 +++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/wyzely_detect/__main__.py b/wyzely_detect/__main__.py index 1b33493..2dce50b 100644 --- a/wyzely_detect/__main__.py +++ b/wyzely_detect/__main__.py @@ -60,7 +60,6 @@ def main(): while True: # Grab a single frame of video 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 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) diff --git a/wyzely_detect/utils/utils.py b/wyzely_detect/utils/utils.py index 102ed77..ed76e55 100644 --- a/wyzely_detect/utils/utils.py +++ b/wyzely_detect/utils/utils.py @@ -124,13 +124,21 @@ def recognize_face( model_name="ArcFace", detector_backend="opencv", ) - except ValueError as e: + + except (ValueError) as e: if ( 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 ): # print("No faces recognized") # For debugging 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: raise e # Iteate over the dataframes