RetinaFace (fastforks)
RetinaFace (Deng et al., CVPR 2020) in the facexlib / Pytorch_Retinaface version: single-stage face detection with five facial landmarks (eyes, nose, mouth corners), the detector of the CodeFormer / GFPGAN face restoration pipelines. A ResNet-50 or MobileNet-0.25 backbone, an FPN, SSH context modules and per-anchor face, box and landmark heads on the stride 8 / 16 / 32 maps. Takes the whole image at its own size (no resize, as facexlib's default use_origin_size=True); vendored from facexlib 0.3.0 (no facexlib / torchvision dependency). The portable module() maps the image to the raw head maps (anchor decoding and NMS stay outside).
This repo is the model card only: it holds no weights. fastforks downloads the authors' weights from the links below and checks them against the SHA-256 in the model card. Code: https://github.com/kleinicke/fastforks. Kernels for the kernels backend: https://huggingface.co/fastforks/kernels. Original code: https://github.com/xinntao/facexlib at 260620ae9399.
Task: pose. Tier: stable. Outputs: keypoints, keypoint_scores, boxes, scores. Backends: portable, kernels.
Input: one RGB image and a box per person. Output: keypoints with confidence scores for every person.
Variants
Weights are the authors' files (not hosted here). SHA-256 shortened to 12 hex digits; the full hashes are in card.toml.
| variant | weights (author link) | SHA-256 | weights licence | commercial use |
|---|---|---|---|---|
retinaface-mobilenet0.25@1 |
detection_mobilenet0.25_Final.pth | 2979b33ffafd |
MIT | yes |
retinaface-resnet50@1 |
detection_Resnet50_Final.pth | 6d1de9c2944f |
MIT | yes |
Licence
Original-code strings, recorded as they are (research-use package; check them before any other use). Code: MIT. Licence files: LICENSE.
Training data: WIDER FACE (32k images, 394k labelled faces) (WIDER FACE train with the RetinaFace five-landmark annotations; the ResNet-50 backbone starts from ImageNet classification weights).
Licence evidence: https://github.com/xinntao/facexlib/blob/260620ae93990a300f4b16448df9bb459f1caba9/README.md
Input size
any H x W >= 32, padded to a multiple of 32
Tested up to (portable, fp16, RTX 5060 Ti 16 GB): retinaface-mobilenet0.25 3000x4000 (0.5 GiB peak allocated, 0.5 reserved); retinaface-resnet50 3000x4000 (1.6 GiB peak allocated, 1.8 reserved)
Speed and memory
Pose, synthetic, 1080x1920
| model | time (ms): original fp32 | original | portable | kernels | kernels speed-up: vs original | vs portable | peak memory (MiB, allocated / reserved): original | portable | kernels |
|---|---|---|---|---|---|---|---|---|---|
retinaface-mobilenet0.25 |
75.9 | 77.4 | 3.44 | 2.74 | 27.7x | 1.3x | 87 / 110 | 86 / 108 | 105 / 128 |
retinaface-resnet50 |
81.0 | 79.4 | 24.3 | 11.7 | 6.8x | 2.1x | 371 / 490 | 405 / 504 | 379 / 464 |
Startup and first call
| model | load (s): original | portable | kernels | first call (s): original | portable | kernels |
|---|---|---|---|---|---|---|
retinaface-mobilenet0.25 |
0.13 | 0.71 | 1.49 | 1.37 | 0.68 | 0.06 |
retinaface-resnet50 |
0.43 | 0.71 | 1.55 | 0.31 | 0.11 | 0.10 |
torch.compile and TensorRT
| model | input | time: portable | compile | TensorRT fp16 | kernels | preparation: compile (cold first call) | ONNX + engine build | peak MiB (alloc / reserved): portable | compile | kernels | TensorRT (engine + torch) |
|---|---|---|---|---|---|---|---|---|---|---|---|
retinaface-mobilenet0.25 |
1080x1920 | 3.44 ms | 2.16 ms | 0.982 ms (network only) | 2.74 ms | 8.87 s | 53.5 s | 86 / 108 | 125 / 148 | 105 / 128 | 133 / 144 |
retinaface-resnet50 |
1080x1920 | 24.3 ms | 16.5 ms | 9.10 ms (network only) | 11.7 ms | 9.56 s | 20.4 s | 405 / 504 | 374 / 444 | 379 / 464 | 451 / 462 |
Fixed-size cells: time (ms) / peak allocated / peak reserved memory (MiB).
Hardware, protocol and caveats: benchmarks (RTX 5060 Ti 16 GB, sm_120). Original = the original code named above at the precision of portable (fp16, or (fp32) where fp16 is unsupported or not finite); original fp32 = its default fp32 run. Peak memory is the torch allocator's.
Accuracy
Parity with the original code
Every variant is checked against reference outputs of the original code at its pinned commit. CPU, float32: max |diff| <= 0.001 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.016 and p99 <= 0.04 (absolute error of the output keypoints).
Limitations
- module() exports the raw per-level head maps; anchor decoding and NMS remain outside the exported graph.
- No per-landmark confidence: keypoint_scores repeats the face score.
- The image is not resized: large photos cost time and memory in proportion to their pixels; downscale them first for big faces.
Usage
from fastforks import pose
model = pose.load("retinaface-mobilenet0.25") # mode="auto": the preferred backend from recorded measurements
result = model("photo.jpg", boxes=[[x0, y0, x1, y1]]) # one box per person, or a fastforks.detection result
result.keypoints, result.keypoint_scores # [P, K, 2] input pixels, [P, K]
result.backend # what ran, e.g. Backend(mode='portable', device='cuda:0', dtype='float16')
Install with pip install fastforks (see https://github.com/kleinicke/fastforks). Other variants: retinaface-mobilenet0.25, retinaface-resnet50.
Kernels backend
pose.load("retinaface-mobilenet0.25", mode="kernels") runs our CUDA kernels (cudnn_hacc, fvm_conv, fvm_extra, fvm_mb, fvm_r3). It needs a prebuilt kernel for your GPU architecture (downloaded from https://huggingface.co/fastforks/kernels on first use) and a recent NVIDIA driver; if there is none it raises BackendUnavailableError with the reason and never falls back silently. mode="auto" picks kernels when it can run and logs the choice.