Compare commits

...

2 Commits

Author SHA1 Message Date
slashtechno 6928fdace5
Added flag to disable TensorFlow using GPU
Added since on Linux, it seems Tensorflow attempts to use GPU by default
2023-12-02 21:23:42 -06:00
slashtechno de5d6c1ab0
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
2023-12-02 18:21:41 -06:00
4 changed files with 41 additions and 6 deletions

12
.vscode/launch.json vendored
View File

@ -22,6 +22,16 @@
"module": "wyzely_detect",
// "justMyCode": true
"justMyCode": false
}
},
{
"name": "Debug --help",
"type": "python",
"request": "launch",
"module": "wyzely_detect",
"args": [
"--help"
],
"justMyCode": false
},
]
}

View File

@ -1,6 +1,6 @@
# import face_recognition
from pathlib import Path
import os
import cv2
# import hjson as json
@ -30,12 +30,22 @@ def main():
# https://github.com/ultralytics/ultralytics/issues/3084#issuecomment-1732433168
# Currently, I have been unable to set up Poetry to use GPU for Torch
for i in range(torch.cuda.device_count()):
print(torch.cuda.get_device_properties(i).name)
print(f'Using {torch.cuda.get_device_properties(i).name} for pytorch')
if torch.cuda.is_available():
torch.cuda.set_device(0)
print("Set CUDA device")
else:
print("No CUDA device available, using CPU")
# Seems automatically, deepface (tensorflow) tried to use my GPU on Pop!_OS (I did not set up cudnn or anything)
# Not sure the best way, in Poetry, to manage GPU libraries so for now, just use CPU
if args.force_disable_tensorflow_gpu:
print("Forcing tensorflow to use CPU")
import tensorflow as tf
tf.config.set_visible_devices([], 'GPU')
if tf.config.experimental.list_logical_devices('GPU'):
print('GPU disabled unsuccessfully')
else:
print("GPU disabled successfully")
model = YOLO("yolov8n.pt")
@ -60,7 +70,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)

View File

@ -72,7 +72,15 @@ def set_argparse():
action="store_true",
help="Don't display the video feed",
)
video_options.add_argument(
'-c',
'--force-disable-tensorflow-gpu',
default=os.environ["FORCE_DISABLE_TENSORFLOW_GPU"]
if "FORCE_DISABLE_TENSORFLOW_GPU" in os.environ and os.environ["FORCE_DISABLE_TENSORFLOW_GPU"] != ""
else False,
action="store_true",
help="Force disable tensorflow GPU through env since sometimes it's not worth it to install cudnn and whatnot",
)
notifcation_services = argparser.add_argument_group("Notification Services")
notifcation_services.add_argument(

View File

@ -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