Merge branch 'master' into fixyunet

This commit is contained in:
Anthr@X 2023-07-14 17:16:38 +10:00 committed by GitHub
commit fc09756cfc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 7 deletions

View File

@ -196,7 +196,7 @@ Age model got ± 4.65 MAE; gender model got 97.44% accuracy, 96.29% precision an
Face detection and alignment are important early stages of a modern face recognition pipeline. Experiments show that just alignment increases the face recognition accuracy almost 1%. [`OpenCV`](https://sefiks.com/2020/02/23/face-alignment-for-face-recognition-in-python-within-opencv/), [`SSD`](https://sefiks.com/2020/08/25/deep-face-detection-with-opencv-in-python/), [`Dlib`](https://sefiks.com/2020/07/11/face-recognition-with-dlib-in-python/), [`MTCNN`](https://sefiks.com/2020/09/09/deep-face-detection-with-mtcnn-in-python/), [`RetinaFace`](https://sefiks.com/2021/04/27/deep-face-detection-with-retinaface-in-python/), [`MediaPipe`](https://sefiks.com/2022/01/14/deep-face-detection-with-mediapipe/), [`YOLOv8 Face`](https://github.com/derronqi/yolov8-face) and [`YuNet`](https://github.com/ShiqiYu/libfacedetection) detectors are wrapped in deepface. Face detection and alignment are important early stages of a modern face recognition pipeline. Experiments show that just alignment increases the face recognition accuracy almost 1%. [`OpenCV`](https://sefiks.com/2020/02/23/face-alignment-for-face-recognition-in-python-within-opencv/), [`SSD`](https://sefiks.com/2020/08/25/deep-face-detection-with-opencv-in-python/), [`Dlib`](https://sefiks.com/2020/07/11/face-recognition-with-dlib-in-python/), [`MTCNN`](https://sefiks.com/2020/09/09/deep-face-detection-with-mtcnn-in-python/), [`RetinaFace`](https://sefiks.com/2021/04/27/deep-face-detection-with-retinaface-in-python/), [`MediaPipe`](https://sefiks.com/2022/01/14/deep-face-detection-with-mediapipe/), [`YOLOv8 Face`](https://github.com/derronqi/yolov8-face) and [`YuNet`](https://github.com/ShiqiYu/libfacedetection) detectors are wrapped in deepface.
<p align="center"><img src="https://raw.githubusercontent.com/serengil/deepface/master/icon/detector-portfolio-v3.jpg" width="95%" height="95%"></p> <p align="center"><img src="https://raw.githubusercontent.com/serengil/deepface/master/icon/detector-portfolio-v5.jpg" width="95%" height="95%"></p>
All deepface functions accept an optional detector backend input argument. You can switch among those detectors with this argument. OpenCV is the default detector. All deepface functions accept an optional detector backend input argument. You can switch among those detectors with this argument. OpenCV is the default detector.

View File

@ -1,21 +1,22 @@
import cv2
import os import os
import cv2
import gdown import gdown
from deepface.detectors import FaceDetector from deepface.detectors import FaceDetector
from deepface.commons import functions from deepface.commons import functions
def build_model(): def build_model():
url = "https://github.com/opencv/opencv_zoo/raw/main/models/face_detection_yunet/face_detection_yunet_2023mar.onnx" 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" file_name = "face_detection_yunet_2023mar.onnx"
home = functions.get_deepface_home() home = functions.get_deepface_home()
if os.path.isfile(home + f"/.deepface/weights/{file_name}") is False: if os.path.isfile(home + f"/.deepface/weights/{file_name}") is False:
print(f"{file_name} will be downloaded...") print(f"{file_name} will be downloaded...")
output = home + f"/.deepface/weights/{file_name}" output = home + f"/.deepface/weights/{file_name}"
gdown.download(url, output, quiet=False) gdown.download(url, output, quiet=False)
face_detector = cv2.FaceDetectorYN_create( face_detector = cv2.FaceDetectorYN_create(home + f"/.deepface/weights/{file_name}", "", (0, 0))
home + f"/.deepface/weights/{file_name}", "", (0, 0)
)
return face_detector return face_detector
@ -72,7 +73,7 @@ def detect_face(detector, image, align=True, score_threshold=0.9):
int(y_le / r), int(y_le / r),
) )
confidence = face[-1] confidence = face[-1]
confidence = "{:.2f}".format(confidence) confidence = f"{confidence:.2f}"
detected_face = image[int(y) : int(y + h), int(x) : int(x + w)] detected_face = image[int(y) : int(y + h), int(x) : int(x + w)]
img_region = [x, y, w, h] img_region = [x, y, w, h]
if align: if align:

Binary file not shown.

After

Width:  |  Height:  |  Size: 200 KiB