RetinaFace

raw JSON →
0.0.2 verified Sat May 09 auth: no python

A Python implementation of RetinaFace, a single-stage dense face localisation model for face detection and landmark localisation in the wild. Current version 0.0.2, requires Python >=3.6, uses PyTorch. The library wraps a pre-trained ResNet50-based RetinaFace model. Release cadence: low (last update likely 2021).

pip install retinaface-py
error ModuleNotFoundError: No module named 'retinaface'
cause Incorrect module name used in import. The correct module is 'RetinaFace' with capital letters.
fix
Use: from RetinaFace import RetinaFace
error TypeError: 'RetinaFace' object is not callable
cause Trying to call the class directly instead of using the static method detect_faces.
fix
Use: detector = RetinaFace(); detections = detector.detect_faces(img) or simply RetinaFace.detect_faces(img)
error ValueError: The truth value of an array with more than one element is ambiguous
cause Passing an image with non-RGB channels (e.g., RGBA) or incorrect dtype.
fix
Ensure image is a 3-channel RGB numpy array with dtype uint8.
gotcha The module name is case-sensitive: 'RetinaFace' not 'retinaface'. Import as 'from RetinaFace import RetinaFace'.
fix Use the correct import statement: from RetinaFace import RetinaFace
gotcha Input image must be a numpy array in RGB format, not BGR. OpenCV loads images as BGR by default.
fix Convert BGR to RGB before passing: img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
deprecated The library is no longer actively maintained; last version 0.0.2 released around 2021. May not work with newer PyTorch versions.
fix Consider using alternative face detection libraries like DeepFace, MTCNN, or dlib.

Detect faces in an image using RetinaFace. The input image should be a numpy array (RGB). Returns a dictionary of detections.


from RetinaFace import RetinaFace
import cv2

# Load image (assuming opencv-python is installed)
img = cv2.imread('face.jpg')
img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

# Detect faces
detections = RetinaFace.detect_faces(img_rgb)

# Print results
for face_id, face_data in detections.items():
    print(f"{face_id}: score={face_data['score']}, box={face_data['facial_area']}")