From b5d95ed963cac67f4aac8ef480b738bdecd4880b Mon Sep 17 00:00:00 2001 From: slashtechno <77907286+slashtechno@users.noreply.github.com> Date: Thu, 2 Nov 2023 19:54:55 -0500 Subject: [PATCH] Fixed unknown face causing error --- .vscode/launch.json | 12 +++++++++++- deepface-test.ipynb | 2 +- wyzely_detect/utils/utils.py | 7 ++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index c613560..66be8e7 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,9 +4,19 @@ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ + { + "name": "Quick Debug", + "type": "python", + "request": "launch", + "module": "wyzely_detect", + "args": [ + "--run-scale", "0.25", "--view-scale", "0.5", "--no-remove-representations" + ], + "justMyCode": true + }, { // "name": "Python: Module", - "name": "Debug Wyzely Detect", + "name": "Full Debug", "type": "python", "request": "launch", "module": "wyzely_detect", diff --git a/deepface-test.ipynb b/deepface-test.ipynb index c7f0bea..aab839a 100644 --- a/deepface-test.ipynb +++ b/deepface-test.ipynb @@ -36,7 +36,7 @@ "# cv2.imwrite(str(uuid_path), frame)\n", "# dfs = DeepFace.find(img_path=str(uuid_path), db_path = \"faces\")\n", "# Don't throw an error if no face is detected (enforce_detection=False)\n", - "dfs = DeepFace.find(frame, db_path = \"faces\", enforce_detection=False, silent=False, model_name=\"ArcFace\", detector_backend=\"opencv\")\n", + "dfs = DeepFace.find(frame, db_path = \"faces\", enforce_detection=True, silent=False, model_name=\"ArcFace\", detector_backend=\"opencv\")\n", "# Get the identity of the person\n", "for i, pd_dataframe in enumerate(dfs):\n", " # Sort the dataframe by confidence\n", diff --git a/wyzely_detect/utils/utils.py b/wyzely_detect/utils/utils.py index d7ffddf..102ed77 100644 --- a/wyzely_detect/utils/utils.py +++ b/wyzely_detect/utils/utils.py @@ -138,7 +138,12 @@ def recognize_face( # The last row is the highest confidence # So we can just grab the path from there # iloc = Integer LOCation - path_to_image = Path(df.iloc[-1]["identity"]) + try: + path_to_image = Path(df.iloc[-1]["identity"]) + # Seems this is caused when someone steps into frame and their face is detected but not recognized + except IndexError: + print("Face present but not recognized") + return None # If the parent name is the same as the path to the database, then set label to the image name instead of the parent name if path_to_image.parent == Path(path_to_directory): label = path_to_image.name