I just want to use RetinaFace conveniently. Most if not all of the codes in this repository are adapted from https://github.com/biubug6/Pytorch_Retinaface.
- remove the torch stuffs
- add onnx based inference
- add auto model downloading
- adapt the detect script for easier usage
- add bounding box squaring option
pip install git+https://github.com/ndgnuh/retinaface_detectorInstall ONNX runtime:
pip install onnxruntime-gpu
# or
pip install onnxruntimeQuick start:
from retinaface_detector import FaceDetector
import cv2
detector = FaceDetector()
cap = cv2.VideoCapture(0)
_, frame = cap.read()
boxes, scores, landmarks = detector(frame)Full settings:
FaceDetector(
model: str = 'mobilenet', # model name, either 'mobilenet' or 'resnet50', anything in the `retinaface_detector/configs.py`
onnx_providers: Collection[str] = onnxruntime.get_available_providers(),
config: dict = None, # default to getattr(configs, model)
confidence_threshold: float = 0.02, # refer to https://github.com/biubug6/Pytorch_Retinaface/blob/master/detect.py
top_k: int = 5000, # refer to https://github.com/biubug6/Pytorch_Retinaface/blob/master/detect.py
keep_top_k: int = 750, # refer to https://github.com/biubug6/Pytorch_Retinaface/blob/master/detect.py
nms_threshold: float = 0.4, # refer to https://github.com/biubug6/Pytorch_Retinaface/blob/master/detect.py
score_threshold: float = 0.6, # refer to https://github.com/biubug6/Pytorch_Retinaface/blob/master/detect.py, it's visualize_threshold there
square_box: Optional[str] = None) # does nothing by default, see below for detailsThis options modify the bounding box to a square:
x1 = max(cx - sz, 0)
x2 = cx + sz
y1 = max(cy - sz, 0)
y2 = cy + szwhere cx, cy are the center coordinates of the box, sz is calculated based on the square_box argument:
"max":max(w, h) // 2"min":min(w, h) // 2"avg":(w + h) // 4
If square_box is None, do nothing.
@inproceedings{deng2019retinaface,
title={RetinaFace: Single-stage Dense Face Localisation in the Wild},
author={Deng, Jiankang and Guo, Jia and Yuxiang, Zhou and Jinke Yu and Irene Kotsia and Zafeiriou, Stefanos},
booktitle={arxiv},
year={2019}