From ab38a1fcf7c9aba9fe31f9243a189b36f847b9ca Mon Sep 17 00:00:00 2001 From: Sefik Ilkin Serengil Date: Sat, 24 Feb 2024 15:31:50 +0000 Subject: [PATCH 1/3] throw meaningful error if yolo weights failed while downloading --- deepface/detectors/Yolo.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/deepface/detectors/Yolo.py b/deepface/detectors/Yolo.py index ed88e63f1..debafc3aa 100644 --- a/deepface/detectors/Yolo.py +++ b/deepface/detectors/Yolo.py @@ -43,8 +43,15 @@ def build_model(self) -> Any: # Download the model's weights if they don't exist if not os.path.isfile(weight_path): - gdown.download(WEIGHT_URL, weight_path, quiet=False) - logger.info(f"Downloaded YOLO model {os.path.basename(weight_path)}") + logger.info(f"Downloading Yolo weights from {WEIGHT_URL} to {weight_path}...") + try: + gdown.download(WEIGHT_URL, weight_path, quiet=False) + except Exception as err: + raise ValueError( + f"Exception while downloading Yolo weights from {WEIGHT_URL}." + f"You may consider to download it to {weight_path} manually." + ) from err + logger.info(f"Yolo model is just downloaded to {os.path.basename(weight_path)}") # Return face_detector return YOLO(weight_path) From 0d18a7c2dfac0afb146e6f4929de6e5bc1b5ee89 Mon Sep 17 00:00:00 2001 From: Sefik Ilkin Serengil Date: Sat, 24 Feb 2024 15:35:26 +0000 Subject: [PATCH 2/3] bug fix in case of load image returns none --- deepface/modules/detection.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/deepface/modules/detection.py b/deepface/modules/detection.py index fc9ef6c94..a1c97b62e 100644 --- a/deepface/modules/detection.py +++ b/deepface/modules/detection.py @@ -76,6 +76,9 @@ def extract_faces( # img might be path, base64 or numpy array. Convert it to numpy whatever it is. img, img_name = preprocessing.load_image(img_path) + if img is None: + raise ValueError(f"Exception while loading {img_name}") + base_region = FacialAreaRegion(x=0, y=0, w=img.shape[1], h=img.shape[0], confidence=0) if detector_backend == "skip": From 644c6b4013bef7d4a3708043e1b5b0291425b453 Mon Sep 17 00:00:00 2001 From: Sefik Ilkin Serengil Date: Sat, 24 Feb 2024 16:24:15 +0000 Subject: [PATCH 3/3] avoid duplicate detections and loadings --- deepface/DeepFace.py | 4 ++-- deepface/modules/{realtime.py => streaming.py} | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) rename deepface/modules/{realtime.py => streaming.py} (99%) diff --git a/deepface/DeepFace.py b/deepface/DeepFace.py index 6d07c86fe..9b2492805 100644 --- a/deepface/DeepFace.py +++ b/deepface/DeepFace.py @@ -19,7 +19,7 @@ recognition, demography, detection, - realtime, + streaming, ) from deepface import __version__ @@ -409,7 +409,7 @@ def stream( time_threshold = max(time_threshold, 1) frame_threshold = max(frame_threshold, 1) - realtime.analysis( + streaming.analysis( db_path=db_path, model_name=model_name, detector_backend=detector_backend, diff --git a/deepface/modules/realtime.py b/deepface/modules/streaming.py similarity index 99% rename from deepface/modules/realtime.py rename to deepface/modules/streaming.py index 8abbda84a..b08616de8 100644 --- a/deepface/modules/realtime.py +++ b/deepface/modules/streaming.py @@ -91,7 +91,7 @@ def analysis( faces = [] for face_obj in face_objs: facial_area = face_obj["facial_area"] - if facial_area["w"] <= 130: # discard small detected faces + if facial_area["w"] <= 130: # discard small detected faces continue faces.append( ( @@ -176,7 +176,7 @@ def analysis( demographies = DeepFace.analyze( img_path=custom_face, - detector_backend=detector_backend, + detector_backend="skip", enforce_detection=False, silent=True, ) @@ -411,7 +411,7 @@ def analysis( img_path=custom_face, db_path=db_path, model_name=model_name, - detector_backend=detector_backend, + detector_backend="skip", distance_metric=distance_metric, enforce_detection=False, silent=True, @@ -429,7 +429,7 @@ def analysis( display_img = cv2.imread(label) # to use extracted face source_objs = DeepFace.extract_faces( - img_path=label, + img_path=display_img, target_size=(pivot_img_size, pivot_img_size), detector_backend=detector_backend, enforce_detection=False,