Install retina-face via pip
masterThe easiest way to install the library and its prerequisites is via PyPI using pip.
$ pip install retina-facerepository·master·Indexed 24 days ago
https://github.com/serengil/retinafaceA deep learning-based facial detector for Python that provides facial landmarks for the eyes, nose, and mouth. It includes functions for face detection via RetinaFace.detect_faces() and face alignment and extraction via RetinaFace.extract_faces(). The library is pip-compatible and can be used as a detector_backend within the DeepFace recognition pipeline.
The easiest way to install the library and its prerequisites is via PyPI using pip.
$ pip install retina-faceIf you need an end-to-end face recognition pipeline (detect, align, normalize, represent, and verify), it is recommended to use the deepface library. You can specify retinaface as the detector_backend when using models like ArcFace.
#!pip install deepface
from deepface import DeepFace
obj = DeepFace.verify("img1.jpg", "img2.jpg", model_name = 'ArcFace', detector_backend = 'retinaface')
print(obj["verified"])To perform face alignment (which can increase face recognition accuracy), use RetinaFace.extract_faces(). By setting align = True, the function uses detected facial landmarks to align the faces during extraction.
This returns a list of extracted face images.
import matplotlib.pyplot as plt
from retinaface import RetinaFace
faces = RetinaFace.extract_faces(img_path = "img.jpg", align = True)
for face in faces:
plt.imshow(face)
plt.show()Use RetinaFace.detect_faces() to perform face detection. It requires the exact path to an image as input.
The method returns a dictionary containing facial area coordinates, landmarks (eyes, nose, and mouth), and a confidence score for each detected face.
from retinaface import RetinaFace
resp = RetinaFace.detect_faces("img1.jpg")The output of detect_faces() is a dictionary where each key is a face identifier (e.g., face_1). Each face object contains:
score: Confidence score of the detection.facial_area: A list containing the coordinates [x1, y1, x2, y2].landmarks: A dictionary containing coordinates for right_eye, left_eye, nose, mouth_right, and mouth_left.{
"face_1": {
"score": 0.9993440508842468,
"facial_area": [155, 81, 434, 443],
"landmarks": {
"right_eye": [257.82974, 209.64787],
"left_eye": [374.93427, 251.78687],
"nose": [303.4773, 299.91144],
"mouth_right": [228.37329, 338.73193],
"mouth_left": [320.21982, 374.58798]
}
}
}