RetinaFace
RetinaFace (ResNet-50, MobileNet-0.25; biubug6 / facexlib): finds faces with a box and five landmarks (eyes, nose, mouth corners); the detector CodeFormer and GFPGAN use for face restoration. MIT.
stable Fork of xinntao/facexlib@260620a · backends: portable, kernels
- Paper RetinaFace: Single-stage Dense Face Localisation in the Wild CVPR 2020 · first released 2 May 2019
- Authors’ code deepinsight/insightface/tree/master/detection/retinaface (MXNet), not the code forked here: The authors' MXNet release has no PyTorch weights; facexlib's PyTorch port (from biubug6/Pytorch_Retinaface) is the detector the face restorers use.
Paper 2019 Added in 0.2.0 Evaluated with 0.2.0
Use it
pip install fastforks Lean install with only what this model needs: pip install fastforks-core
from fastforks import pose
model = pose.load("retinaface-resnet50") # kernels on a supported GPU, else portable PyTorch
result = model(image, boxes=...)
result.keypoints # also: keypoint_scores, boxes, scores
result.backend # what ran: mode, device, dtype, kernels fastforks bench retinaface-resnet50 Times the model on this machine. load(…, mode="portable") or mode="kernels" picks a backend; usage guide.
Speed and memory
Every backend on one GPU (RTX 5060 Ti 16 GB) and the same input, the authors’ code included. Kernels runs fp16. Portable runs fp16 on CUDA.
Input: synthetic, 1080x1920 (the task’s standard size)
| Backend | dtype | Time per call (ms) | vs original fp16 | Peak memory allocated / reserved | Load (s) | First call (s) |
|---|---|---|---|---|---|---|
| Original fp32facexlib 0.3.0 detect_faces (use_origin_size, float32): preprocessing, network, NMS, decode | fp32 | 81.0 | 0.98× | 545 MiB/648 MiB | 1.9 | 0.48 |
| Original fp16torch.autocast(float16) around the call; facexlib 0.3.0 detect_faces (use_origin_size, float32): preprocessing, network, NMS, decode | fp16 | 79.4 | – | 371 MiB/490 MiB | 0.4 | 0.31 |
| Portable fp32 | fp32 | not measured | – | – | – | – |
| Portable | fp16 | 24.3 | 3.3× | 405 MiB/504 MiB | 0.7 | 0.11 |
| Kernels | fp16 | 11.7 | 6.8× | 379 MiB/464 MiB | 1.6 | 0.10 |
| Portable + torch.compile | 16.5 | 4.8× | 374 MiB/444 MiB | 10 (build) | – | |
| TensorRT fp16network only | fp16 | 9.10 | 8.7× | 242 MiBenginenot comparable | 20 (build) | – |
Measured on RTX 5060 Ti 16 GB, torch 2.14.1+cu130, 2026-11-13. First call, 3 warm-up, peak reset, median of 3 rounds x median of 5. Ratios divide two
times of this table (same GPU, same input). Original fp16 is the authors’ own precision option, else torch.autocast. torch.compile and TensorRT: build time instead of load time. TensorRT memory (engine, not comparable) is the GPU memory the engine took, read from the driver because TensorRT allocates outside PyTorch, so it can't be compared with the PyTorch peaks of the other rows.
Other devices
| Device | Backend | dtype | ms / call | Peak memory | Output vs reference | Input |
|---|---|---|---|---|---|---|
| Apple M1 Pro 16 GB MPS, torch 2.14.1, 2026-11-14 | Original | fp32 | 256 | 1,871 MiB process | – | 1080x1920 |
| Portable | fp16 | 150 | 1,913 MiB process | matches | 1080x1920 | |
| Portable | fp32 | 210 | 1,879 MiB process | matches | 1080x1920 | |
| Kernels | fp16 | not implemented | – | 1080x1920 | ||
CUDA memory is torch’s peak allocated / reserved; Apple has no such counter, so the Mac rows show the process footprint (weights, Python and torch included). “Output vs reference” compares the device’s output with the stored golden output under the card’s tolerance; – = not checked on that device. Kernels “not implemented” = no kernels for this model on that backend yet: it runs portable there.
Licence and weights
Commercial use allowed
- Code
- MIT LICENSE
- Weights
- MIT source
- Training data
-
- WIDER FACE (32k images, 394k labelled faces) research-only, non-commercial
Our reading of the licences, not legal advice.
Weights
detection_Resnet50_Final.pth 109 MB· hosted on GitHubfastforks downloads and checks these files on first use (fastforks download retinaface-resnet50).
Accuracy
The test set through the authors’ code and through ours: same checkpoint, same protocol. The distance between the original’s fp32 and fp16 runs is what half precision alone costs; our runs should stay within it.
WIDER FACE val
every 4th image (807), face box AP easy / medium / hard
| Run | dtype | ap_easy ↑ | ap_medium ↑ | ap_hard ↑ | Δ ap_easy vs fp32 original | images | ms / image |
|---|---|---|---|---|---|---|---|
| Original fp32 | fp32 | 0.954 | 0.939 | 0.841 | reference | 807 | – |
| Original fp16 | not measured | ||||||
| Portable fp32 | fp32 | 0.954 | 0.940 | 0.841 | ±0.000 | 807 | 21.8 |
| Portable | fp16 | 0.954 | 0.939 | 0.840 | ±0.000 | 807 | – |
| Kernels | fp16 | 0.954 | 0.939 | 0.840 | ±0.000 | 807 | – |
Each image at its own size, score threshold 0.02 and NMS IoU 0.45 (the authors' evaluation settings), the official toolkit's AP at IoU 0.5 over the subset's faces. Original = the authors’ code, same checkpoint and protocol. Measured on original fp32: RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-16; portable fp32: RTX 5060 Ti, torch 2.14.1+cu130, fastforks 3bf0bac7, 2026-11-17; portable, kernels: RTX 5060 Ti, torch 2.14.1+cu130, fastforks 68b2f345, 2026-11-16.
Closeness to the original
Beyond the test-set scores: the raw output of ours against the original’s fp32 output on the same input, pixel by pixel. 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).
| Check | Tolerance | Measured |
|---|---|---|
| CPU fp32, max |diff| | ≤ 0.001 | not recorded |
| GPU default dtypes, mean |diff| | ≤ 0.016 | 0.00589 |
| GPU default dtypes, p99 |diff| | ≤ 0.04 | 0.01506 |
| gpu_min_score | ≤ 0.3 | not recorded |
Recorded for retinaface-resnet50 on RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-13, with these kernels: cudnn_haccfvm_convfvm_extrafvm_mbfvm_r3
Details
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).
- Input / output
- Input: one RGB image and a box per person. Output: keypoints with confidence scores for every person.
- Input size
- any H x W >= 32, padded to a multiple of 32; tested up to 3000x4000 (1,603 MiB allocated)
- Options
score_threshold=0.80.0 to 1.0· changes the output
- Outputs
keypoints,keypoint_scores,boxes,scores- Checkpoint
backbone="resnet50"- CUDA kernels
cudnn_haccconvolutions with fp16 accumulation (cuDNN)fvm_convfused convolutions for image classifiersfvm_extrafused transformer row operations (rotary split, SwiGLU with LayerNorm)fvm_mbfused MBConv blocks (MobileNet and EfficientNet families)fvm_r3further fused classifier blocks
- Apple (MPS)
- fp32, fp16
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.
Full reference, generated from the repository
RetinaFace (ResNet-50, MobileNet-0.25; biubug6 / facexlib): finds faces with a box and five landmarks (eyes, nose, mouth corners); the detector CodeFormer and GFPGAN use for face restoration. MIT.
Commercial use: yes.
| variant | input | backend | time (ms) | peak memory (MiB, allocated / reserved) |
|---|---|---|---|---|
retinaface-resnet50 | synthetic (1080x1920) | original (fp32) original portable kernels portable + torch.compile TensorRT fp16 | 81.0 79.4 24.3 11.7 16.5 9.10 (network only) | 545 / 648 371 / 490 405 / 504 379 / 464 374 / 444 451 / 462 |
retinaface-mobilenet0.25 | synthetic (1080x1920) | original (fp32) original portable kernels portable + torch.compile TensorRT fp16 | 75.9 77.4 3.44 2.74 2.16 0.982 (network only) | 110 / 128 87 / 110 86 / 108 105 / 128 125 / 148 133 / 144 |
Details
- Original code: https://github.com/xinntao/facexlib at
260620ae9399 - Code licence: MIT (permissive); files:
LICENSE - Weights licence: MIT
- Licence evidence: https://github.com/xinntao/facexlib/blob/260620ae93990a300f4b16448df9bb459f1caba9/README.md
- 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)
- Options:
score_threshold= 0.8 (0.0 to 1.0) - Kernel libraries:
cudnn_hacc,fvm_conv,fvm_extra,fvm_mb,fvm_r3 - Variants:
retinaface-resnet50,retinaface-mobilenet0.25 - Outputs: keypoints, keypoint_scores, boxes, scores; label_set:
face-5 - Input size: any H x W >= 32, padded to a multiple of 32
- Tested up to (portable, fp16, RTX 5060 Ti 16 GB):
retinaface-resnet503000x4000 (1.6 GiB peak allocated, 1.8 reserved);retinaface-mobilenet0.253000x4000 (0.5 GiB peak allocated, 0.5 reserved) retinaface-resnet501080x1920, first call: portable + torch.compile 10 s (cold Inductor cache), TensorRT fp16 20 s (ONNX + engine).retinaface-mobilenet0.251080x1920, first call: portable + torch.compile 9 s (cold Inductor cache), TensorRT fp16 54 s (ONNX + engine).retinaface-resnet50original (fp32) 1080x1920: facexlib 0.3.0 detect_faces (use_origin_size, float32): preprocessing, network, NMS, decoderetinaface-resnet50original 1080x1920: torch.autocast(float16) around the call; facexlib 0.3.0 detect_faces (use_origin_size, float32): preprocessing, network, NMS, decoderetinaface-mobilenet0.25original (fp32) 1080x1920: facexlib 0.3.0 detect_faces (use_origin_size, float32): preprocessing, network, NMS, decoderetinaface-mobilenet0.25original 1080x1920: torch.autocast(float16) around the call; facexlib 0.3.0 detect_faces (use_origin_size, float32): preprocessing, network, NMS, decoderetinaface-resnet50load / first call: original 0.43 s / 0.306 s, portable 0.71 s / 0.111 s, kernels 1.55 s / 0.104 sretinaface-mobilenet0.25load / first call: original 0.13 s / 1.369 s, portable 0.71 s / 0.677 s, kernels 1.49 s / 0.064 s- Protocol, first call, 3 warm-up, peak reset, median of 3 rounds x median of 5
Measured
Each image at its own size, score threshold 0.02 and NMS IoU 0.45 (the authors' evaluation settings), the official toolkit's AP at IoU 0.5 over the subset's faces. Original = the original code named under Details, same checkpoint and protocol.
| variant | dataset | original fp32 | portable | portable fp32 | kernels | note |
|---|---|---|---|---|---|---|
retinaface-resnet50 | WIDER FACE val, every 4th image (807), face box AP easy / medium / hard | 0.954 / 0.939 / 0.841 | 0.954 / 0.939 / 0.840 | 0.954 / 0.940 / 0.841 | 0.954 / 0.939 / 0.840 | |
retinaface-mobilenet0.25 | WIDER FACE val, every 4th image (807), face box AP easy / medium / hard | 0.905 / 0.882 / 0.741 | 0.905 / 0.882 / 0.741 |
Measured on portable: NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 68b2f345, 2026-11-16; portable32: NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 3bf0bac7, 2026-11-17; kernels: NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 68b2f345, 2026-11-16.
Parity
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).
| variant | kernels error vs original, mean / p99 | GPU, torch | kernels used |
|---|---|---|---|
retinaface-resnet50 | 0.00589 / 0.01506 | RTX 5060 Ti, torch 2.14.1+cu130 | cudnn_hacc@cudnn92400, fvm_conv@f1d064e539e1:sm_120, fvm_extra@3208ce525a91:sm_120, fvm_mb@720dd3f29bf7:sm_120, fvm_r3@f54eb890e23c:sm_120 |
retinaface-mobilenet0.25 | 0.01056 / 0.02666 | RTX 5060 Ti, torch 2.14.1+cu130 | cudnn_hacc@cudnn92400, fvm_conv@f1d064e539e1:sm_120, fvm_extra@3208ce525a91:sm_120, fvm_mb@720dd3f29bf7:sm_120, fvm_r3@f54eb890e23c:sm_120 |
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.
Example output
No example rendered for this checkpoint yet.