From 769a4978963935b1170d76313ccf766fab99b7f3 Mon Sep 17 00:00:00 2001 From: Vincent STRAGIER Date: Tue, 23 May 2023 23:54:21 +0200 Subject: [PATCH 1/5] Correct laterality of the eyes landmarks. --- deepface/detectors/MediapipeWrapper.py | 44 ++++++++++++-------------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/deepface/detectors/MediapipeWrapper.py b/deepface/detectors/MediapipeWrapper.py index 74cffff46..5cf27daad 100644 --- a/deepface/detectors/MediapipeWrapper.py +++ b/deepface/detectors/MediapipeWrapper.py @@ -19,35 +19,31 @@ def detect_face(face_detector, img, align=True): results = face_detector.process(img) - if results.detections: - for detection in results.detections: + for detection in results.detections: + (confidence,) = detection.score - (confidence,) = detection.score + bounding_box = detection.location_data.relative_bounding_box + landmarks = detection.location_data.relative_keypoints - bounding_box = detection.location_data.relative_bounding_box - landmarks = detection.location_data.relative_keypoints + x = int(bounding_box.xmin * img_width) + w = int(bounding_box.width * img_width) + y = int(bounding_box.ymin * img_height) + h = int(bounding_box.height * img_height) - x = int(bounding_box.xmin * img_width) - w = int(bounding_box.width * img_width) - y = int(bounding_box.ymin * img_height) - h = int(bounding_box.height * img_height) + left_eye = (int(landmarks[0].x * img_width), int(landmarks[0].y * img_height)) + right_eye = (int(landmarks[1].x * img_width), int(landmarks[1].y * img_height)) + # nose = (int(landmarks[2].x * img_width), int(landmarks[2].y * img_height)) + # mouth = (int(landmarks[3].x * img_width), int(landmarks[3].y * img_height)) + # right_ear = (int(landmarks[4].x * img_width), int(landmarks[4].y * img_height)) + # left_ear = (int(landmarks[5].x * img_width), int(landmarks[5].y * img_height)) - right_eye = (int(landmarks[0].x * img_width), int(landmarks[0].y * img_height)) - left_eye = (int(landmarks[1].x * img_width), int(landmarks[1].y * img_height)) - # nose = (int(landmarks[2].x * img_width), int(landmarks[2].y * img_height)) - # mouth = (int(landmarks[3].x * img_width), int(landmarks[3].y * img_height)) - # right_ear = (int(landmarks[4].x * img_width), int(landmarks[4].y * img_height)) - # left_ear = (int(landmarks[5].x * img_width), int(landmarks[5].y * img_height)) + if x > 0 and y > 0: + detected_face = img[y : y + h, x : x + w] + img_region = [x, y, w, h] - if x > 0 and y > 0: - detected_face = img[y : y + h, x : x + w] - img_region = [x, y, w, h] + if align: + detected_face = FaceDetector.alignment_procedure(detected_face, left_eye, right_eye) - if align: - detected_face = FaceDetector.alignment_procedure( - detected_face, left_eye, right_eye - ) - - resp.append((detected_face, img_region, confidence)) + resp.append((detected_face, img_region, confidence)) return resp From 907db28625f6bc06b38ec1569ed9170d181dc63d Mon Sep 17 00:00:00 2001 From: Vincent STRAGIER Date: Wed, 24 May 2023 20:50:49 +0200 Subject: [PATCH 2/5] Restore "no result" guard. --- deepface/detectors/MediapipeWrapper.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/deepface/detectors/MediapipeWrapper.py b/deepface/detectors/MediapipeWrapper.py index 5cf27daad..51abade98 100644 --- a/deepface/detectors/MediapipeWrapper.py +++ b/deepface/detectors/MediapipeWrapper.py @@ -19,6 +19,10 @@ def detect_face(face_detector, img, align=True): results = face_detector.process(img) + # if no face have been detected, return an empty list + if results.detections is None: + return resp + for detection in results.detections: (confidence,) = detection.score From c96a2e445633d80278a0e85f86b6df79a39c1b29 Mon Sep 17 00:00:00 2001 From: Vincent STRAGIER Date: Mon, 5 Jun 2023 12:30:57 +0200 Subject: [PATCH 3/5] Add some comments. --- deepface/detectors/MediapipeWrapper.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/deepface/detectors/MediapipeWrapper.py b/deepface/detectors/MediapipeWrapper.py index 51abade98..575348587 100644 --- a/deepface/detectors/MediapipeWrapper.py +++ b/deepface/detectors/MediapipeWrapper.py @@ -19,10 +19,11 @@ def detect_face(face_detector, img, align=True): results = face_detector.process(img) - # if no face have been detected, return an empty list + # If no face has been detected, return an empty list if results.detections is None: return resp + # Extract the bounding box, the landmarks and the confidence score for detection in results.detections: (confidence,) = detection.score @@ -34,6 +35,7 @@ def detect_face(face_detector, img, align=True): y = int(bounding_box.ymin * img_height) h = int(bounding_box.height * img_height) + # Extract landmarks left_eye = (int(landmarks[0].x * img_width), int(landmarks[0].y * img_height)) right_eye = (int(landmarks[1].x * img_width), int(landmarks[1].y * img_height)) # nose = (int(landmarks[2].x * img_width), int(landmarks[2].y * img_height)) From 011a0987a7a2ef4e849f0a185fd18843a9d8bffb Mon Sep 17 00:00:00 2001 From: miawoltn Date: Sun, 11 Jun 2023 07:38:27 +0100 Subject: [PATCH 4/5] enhancement for deepface home path creation --- deepface/commons/functions.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/deepface/commons/functions.py b/deepface/commons/functions.py index 562e8162e..11eb2d8ec 100644 --- a/deepface/commons/functions.py +++ b/deepface/commons/functions.py @@ -36,13 +36,15 @@ def initialize_folder(): OSError: if the folder cannot be created. """ home = get_deepface_home() + deepFaceHomePath = home + "/.deepface" + weightsPath = deepFaceHomePath + "/weights" - if not os.path.exists(home + "/.deepface"): - os.makedirs(home + "/.deepface") + if not os.path.exists(deepFaceHomePath): + os.makedirs(deepFaceHomePath, exist_ok=True) print("Directory ", home, "/.deepface created") - if not os.path.exists(home + "/.deepface/weights"): - os.makedirs(home + "/.deepface/weights") + if not os.path.exists(weightsPath): + os.makedirs(weightsPath, exist_ok=True) print("Directory ", home, "/.deepface/weights created") From 2fd5cc19493bfcd4e630e36fdeed0e6dcbd2ad34 Mon Sep 17 00:00:00 2001 From: Sefik Ilkin Serengil Date: Fri, 16 Jun 2023 12:28:24 +0100 Subject: [PATCH 5/5] Update README.md --- README.md | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/README.md b/README.md index 9e59f40c0..a0cd1338c 100644 --- a/README.md +++ b/README.md @@ -313,18 +313,6 @@ $ deepface analyze -img_path tests/dataset/img1.jpg You can also run these commands if you are running deepface with docker. Please follow the instructions in the [shell script](https://github.com/serengil/deepface/blob/master/scripts/dockerize.sh#L17). -## Derived applications - -You can use deepface not just for facial recognition tasks. It's very common to use DeepFace for entertainment purposes. For instance, celebrity look-alike prediction and parental look-alike prediction tasks can be done with DeepFace! - -**Parental Look-Alike Prediction** - [`Vlog`](https://youtu.be/nza4tmi9vhE), [`Tutorial`](https://sefiks.com/2022/12/22/decide-whom-your-child-looks-like-with-facial-recognition-mommy-or-daddy/) - -

- -**Celebrity Look-Alike Prediction** - [`Vlog`](https://youtu.be/jaxkEn-Kieo), [`Tutorial`](https://sefiks.com/2019/05/05/celebrity-look-alike-face-recognition-with-deep-learning-in-keras/) - -

- ## Contribution [![Tests](https://github.com/serengil/deepface/actions/workflows/tests.yml/badge.svg)](https://github.com/serengil/deepface/actions/workflows/tests.yml) Pull requests are more than welcome! You should run the unit tests locally by running [`test/unit_tests.py`](https://github.com/serengil/deepface/blob/master/tests/unit_tests.py) before creating a PR. Once a PR sent, GitHub test workflow will be run automatically and unit test results will be available in [GitHub actions](https://github.com/serengil/deepface/actions) before approval. Besides, workflow will evaluate the code with pylint as well.