From 498658d0849b6af4debaf9c26f5e2cce924e8987 Mon Sep 17 00:00:00 2001 From: "Anthr@X" Date: Thu, 13 Jul 2023 11:17:09 +1000 Subject: [PATCH 1/5] Fix yunet return negative coordinates --- deepface/detectors/YunetWrapper.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/deepface/detectors/YunetWrapper.py b/deepface/detectors/YunetWrapper.py index dc7b1b2..cc15e03 100644 --- a/deepface/detectors/YunetWrapper.py +++ b/deepface/detectors/YunetWrapper.py @@ -52,6 +52,10 @@ def detect_face(detector, image, align=True, score_threshold=0.9): {x, y}_{re, le, nt, rcm, lcm} stands for the coordinates of right eye, left eye, nose tip, the right corner and left corner of the mouth respectively. """ (x, y, w, h, x_re, y_re, x_le, y_le) = list(map(int, face[:8])) + if x < 0: + x = 0 + if y < 0: + y = 0 if resized: image = original_image x, y, w, h = int(x / r), int(y / r), int(w / r), int(h / r) From b97f74e18679fdc2271b3baefa5aca7c7b340d3f Mon Sep 17 00:00:00 2001 From: "Anthr@X" Date: Thu, 13 Jul 2023 22:13:32 +1000 Subject: [PATCH 2/5] fix linting and add comments --- deepface/detectors/YunetWrapper.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/deepface/detectors/YunetWrapper.py b/deepface/detectors/YunetWrapper.py index cc15e03..eeaa265 100644 --- a/deepface/detectors/YunetWrapper.py +++ b/deepface/detectors/YunetWrapper.py @@ -13,9 +13,7 @@ def build_model(): print(f"{file_name} will be downloaded...") output = home + f"/.deepface/weights/{file_name}" gdown.download(url, output, quiet=False) - face_detector = cv2.FaceDetectorYN_create( - home + f"/.deepface/weights/{file_name}", "", (0, 0) - ) + face_detector = cv2.FaceDetectorYN_create(home + f"/.deepface/weights/{file_name}", "", (0, 0)) return face_detector @@ -52,10 +50,11 @@ def detect_face(detector, image, align=True, score_threshold=0.9): {x, y}_{re, le, nt, rcm, lcm} stands for the coordinates of right eye, left eye, nose tip, the right corner and left corner of the mouth respectively. """ (x, y, w, h, x_re, y_re, x_le, y_le) = list(map(int, face[:8])) - if x < 0: - x = 0 - if y < 0: - y = 0 + + # Yunet returns negative coordinates if it thinks part of the detected face is outside the frame. + # We set the coordinate to 0 if they are negative. + x = max(x, 0) + y = max(y, 0) if resized: image = original_image x, y, w, h = int(x / r), int(y / r), int(w / r), int(h / r) From a456b43d57ec0bd0c23dfac42e419ca41be89624 Mon Sep 17 00:00:00 2001 From: "Anthr@X" Date: Fri, 14 Jul 2023 14:34:05 +1000 Subject: [PATCH 3/5] fix line too long --- deepface/detectors/YunetWrapper.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/deepface/detectors/YunetWrapper.py b/deepface/detectors/YunetWrapper.py index eeaa265..6fcf762 100644 --- a/deepface/detectors/YunetWrapper.py +++ b/deepface/detectors/YunetWrapper.py @@ -13,7 +13,9 @@ def build_model(): print(f"{file_name} will be downloaded...") output = home + f"/.deepface/weights/{file_name}" gdown.download(url, output, quiet=False) - face_detector = cv2.FaceDetectorYN_create(home + f"/.deepface/weights/{file_name}", "", (0, 0)) + face_detector = cv2.FaceDetectorYN_create( + home + f"/.deepface/weights/{file_name}", "", (0, 0) + ) return face_detector From 3e7f6dfb585527cbe8bd96e989daf90283fb70a6 Mon Sep 17 00:00:00 2001 From: "Anthr@X" Date: Fri, 14 Jul 2023 14:57:20 +1000 Subject: [PATCH 4/5] fix comment length --- deepface/detectors/YunetWrapper.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/deepface/detectors/YunetWrapper.py b/deepface/detectors/YunetWrapper.py index 6fcf762..c36c182 100644 --- a/deepface/detectors/YunetWrapper.py +++ b/deepface/detectors/YunetWrapper.py @@ -45,15 +45,20 @@ def detect_face(detector, image, align=True, score_threshold=0.9): for face in faces: """ The detection output faces is a two-dimension array of type CV_32F, - whose rows are the detected face instances, columns are the location of a face and 5 facial landmarks. + whose rows are the detected face instances, columns are the location + of a face and 5 facial landmarks. The format of each row is as follows: - x1, y1, w, h, x_re, y_re, x_le, y_le, x_nt, y_nt, x_rcm, y_rcm, x_lcm, y_lcm, - where x1, y1, w, h are the top-left coordinates, width and height of the face bounding box, - {x, y}_{re, le, nt, rcm, lcm} stands for the coordinates of right eye, left eye, nose tip, the right corner and left corner of the mouth respectively. + x1, y1, w, h, x_re, y_re, x_le, y_le, x_nt, y_nt, + x_rcm, y_rcm, x_lcm, y_lcm, + where x1, y1, w, h are the top-left coordinates, width and height of + the face bounding box, + {x, y}_{re, le, nt, rcm, lcm} stands for the coordinates of right eye, + left eye, nose tip, the right corner and left corner of the mouth respectively. """ (x, y, w, h, x_re, y_re, x_le, y_le) = list(map(int, face[:8])) - # Yunet returns negative coordinates if it thinks part of the detected face is outside the frame. + # Yunet returns negative coordinates if it thinks part of + # the detected face is outside the frame. # We set the coordinate to 0 if they are negative. x = max(x, 0) y = max(y, 0) From 9bf95422731697e5dfd4654295bd6961e1a488e6 Mon Sep 17 00:00:00 2001 From: "Anthr@X" Date: Mon, 24 Jul 2023 15:54:34 +1000 Subject: [PATCH 5/5] fix linter errors --- deepface/detectors/YunetWrapper.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/deepface/detectors/YunetWrapper.py b/deepface/detectors/YunetWrapper.py index cc3d3d3..05d990a 100644 --- a/deepface/detectors/YunetWrapper.py +++ b/deepface/detectors/YunetWrapper.py @@ -6,10 +6,8 @@ from deepface.commons import functions def build_model(): - url = ( - "https://github.com/opencv/opencv_zoo/raw/main/models/" - + "face_detection_yunet/face_detection_yunet_2023mar.onnx" - ) + # pylint: disable=C0301 + url = "https://github.com/opencv/opencv_zoo/raw/main/models/face_detection_yunet/face_detection_yunet_2023mar.onnx" file_name = "face_detection_yunet_2023mar.onnx" home = functions.get_deepface_home() if os.path.isfile(home + f"/.deepface/weights/{file_name}") is False: @@ -44,9 +42,10 @@ def detect_face(detector, image, align=True, score_threshold=0.9): if faces is None: return resp for face in faces: + # pylint: disable=W0105 """ The detection output faces is a two-dimension array of type CV_32F, - whose rows are the detected face instances, columns are the location + whose rows are the detected face instances, columns are the location of a face and 5 facial landmarks. The format of each row is as follows: x1, y1, w, h, x_re, y_re, x_le, y_le, x_nt, y_nt, @@ -58,7 +57,7 @@ def detect_face(detector, image, align=True, score_threshold=0.9): """ (x, y, w, h, x_re, y_re, x_le, y_le) = list(map(int, face[:8])) - # Yunet returns negative coordinates if it thinks part of + # Yunet returns negative coordinates if it thinks part of # the detected face is outside the frame. # We set the coordinate to 0 if they are negative. x = max(x, 0)