YuNet
YuNet (Wu, Peng, Yu, Shenzhen University; libfacedetection.train): a tiny face detector (YuNet-n 75 k, YuNet-s 55 k parameters, OpenCV's FaceDetectorYN) that finds faces with a box and five landmarks. BSD-3-Clause code and weights.
stable Fork of ShiqiYu/libfacedetection.train@dca340a · backends: portable, kernels
- Paper YuNet: A Tiny Millisecond-level Face Detector Machine Intelligence Research 2023 · first released 15 May 2023
- Authors’ code opencv/opencv_zoo/tree/main/models/face_detection_yunet (ONNX (OpenCV DNN)), not the code forked here: The OpenCV Zoo ships the same network as ONNX for `cv2.FaceDetectorYN`; the PyTorch weights and the WIDER FACE evaluation are libfacedetection.train's.
Paper 2023 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("yunet-n") # 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 yunet-n 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 fp32 | fp32 | not measured | – | – | – | – |
| Original fp16torch.autocast(float16) around the call; libfacedetection.train build_yunet + YuNetPostprocessor (origin size, float32): upload, pad, network, NMS | fp16 | 6.04 | – | 134 MiB/168 MiB | 0.2 | 0.97 |
| Portable fp32 | fp32 | not measured | – | – | – | – |
| Portable | fp16 | 2.95 | 2.0× | 96 MiB/124 MiB | 0.6 | 0.23 |
| Kernels | fp16 | 2.22 | 2.7× | 84 MiB/104 MiB | 1.9 | 0.07 |
| Portable + torch.compile | 1.79 | 3.4× | 124 MiB/144 MiB | 8 (build) | – | |
| TensorRT fp16network only | fp16 | 0.794 | 7.6× | 68 MiBenginenot comparable | 12 (build) | – |
Measured on RTX 5060 Ti 16 GB, torch 2.14.1+cu130, 2026-11-14. 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-15 | Original | fp32 | 34.1 | 1,453 MiB process | – | 1080x1920 |
| Portable | fp16 | 21.6 | 1,377 MiB process | matches | 1080x1920 | |
| Portable | fp32 | 24.9 | 1,380 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
- BSD-3-Clause LICENSE
- Weights
- BSD-3-Clause source
- Training data
-
- WIDER FACE (32k images, 394k labelled faces) research-only, non-commercial
Our reading of the licences, not legal advice.
Weights
yunet_n.pth 747 KB· hosted on GitHubfastforks downloads and checks these files on first use (fastforks download yunet-n).
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.894 | 0.883 | 0.810 | reference | 807 | – |
| Original fp16 | not measured | ||||||
| Portable fp32 | fp32 | 0.894 | 0.883 | 0.810 | ±0.000 | 807 | – |
| Portable | fp16 | 0.893 | 0.883 | 0.810 | −0.000 | 807 | – |
| Kernels | fp16 | 0.894 | 0.883 | 0.810 | −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-14; portable fp32, portable, kernels: RTX 5060 Ti, torch 2.14.1+cu130, fastforks f104019b, 2026-11-14.
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.1 and p99 <= 0.3 (absolute error of the output keypoints).
| Check | Tolerance | Measured |
|---|---|---|
| CPU fp32, max |diff| | ≤ 0.001 | not recorded |
| GPU default dtypes, mean |diff| | ≤ 0.1 | 0.0218 |
| GPU default dtypes, p99 |diff| | ≤ 0.3 | 0.03939 |
| gpu_min_score | ≤ 0.3 | not recorded |
Recorded for yunet-n on RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-14, with these kernels: cudnn_haccfvm_convfvm_extrafvm_mbfvm_r3
Details
YuNet (Wu et al., Machine Intelligence Research 2023): a 75k-parameter anchor-free face detector with five facial landmarks, the network behind libfacedetection and OpenCV's `FaceDetectorYN` (OpenCV Zoo `face_detection_yunet`). Depthwise-separable backbone, a tiny top-down FPN and per-cell class / objectness / box / landmark heads on the stride 8 / 16 / 32 maps. Takes the whole image at its own size (padded to multiples of 32, as upstream's WIDER FACE evaluation); vendored from libfacedetection.train's PyTorch code. The portable `module()` maps the image to the raw head maps (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 (552 MiB allocated)
- Options
score_threshold=0.60.0 to 1.0· changes the output
- Outputs
keypoints,keypoint_scores,boxes,scores- 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; decoding and NMS remain outside the exported graph.
- No per-landmark confidence: keypoint_scores repeats the face score.
- The image is not resized: faces much smaller than about 10 px are missed; large photos cost time in proportion to their pixels.
Full reference, generated from the repository
YuNet (Wu, Peng, Yu, Shenzhen University; libfacedetection.train): a tiny face detector (YuNet-n 75 k, YuNet-s 55 k parameters, OpenCV's FaceDetectorYN) that finds faces with a box and five landmarks. BSD-3-Clause code and weights.
Commercial use: yes.
| variant | input | backend | time (ms) | peak memory (MiB, allocated / reserved) |
|---|---|---|---|---|
yunet-n | synthetic (1080x1920) | original portable kernels portable + torch.compile TensorRT fp16 | 6.04 2.95 2.22 1.79 0.794 (network only) | 134 / 168 96 / 124 84 / 104 124 / 144 119 / 150 |
yunet-s | synthetic (1080x1920) | original portable kernels portable + torch.compile TensorRT fp16 | 5.55 2.67 2.00 1.65 0.680 (network only) | 118 / 148 96 / 124 84 / 104 124 / 144 114 / 146 |
Details
- Original code: https://github.com/ShiqiYu/libfacedetection.train at
dca340aa082c - Code licence: BSD-3-Clause (permissive); files:
LICENSE - Weights licence: BSD-3-Clause
- Licence evidence: https://github.com/ShiqiYu/libfacedetection.train/blob/dca340aa082c71081a68d17db8e58b33a58a914b/LICENSE
- Training data: WIDER FACE (32k images, 394k labelled faces) (WIDER FACE train with the SCRFD five-landmark annotations (labelv2), from scratch)
- Options:
score_threshold= 0.6 (0.0 to 1.0) - Kernel libraries:
cudnn_hacc,fvm_conv,fvm_extra,fvm_mb,fvm_r3 - Variants:
yunet-n,yunet-s - 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):
yunet-n3000x4000 (0.5 GiB peak allocated, 0.6 reserved);yunet-s3000x4000 (0.5 GiB peak allocated, 0.6 reserved) yunet-n1080x1920, first call: portable + torch.compile 8 s (cold Inductor cache), TensorRT fp16 12 s (ONNX + engine).yunet-s1080x1920, first call: portable + torch.compile 8 s (cold Inductor cache), TensorRT fp16 13 s (ONNX + engine).yunet-noriginal 1080x1920: torch.autocast(float16) around the call; libfacedetection.train build_yunet + YuNetPostprocessor (origin size, float32): upload, pad, network, NMSyunet-soriginal 1080x1920: torch.autocast(float16) around the call; libfacedetection.train build_yunet + YuNetPostprocessor (origin size, float32): upload, pad, network, NMSyunet-nload / first call: original 0.49 s / 0.477 s, portable 0.61 s / 0.23 s, kernels 1.91 s / 0.071 syunet-sload / first call: original 0.19 s / 0.009 s, portable 0.57 s / 0.281 s, kernels 0.59 s / 0.062 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 |
|---|---|---|---|---|---|---|
yunet-n | WIDER FACE val, every 4th image (807), face box AP easy / medium / hard | 0.894 / 0.883 / 0.810 | 0.893 / 0.883 / 0.810 | 0.894 / 0.883 / 0.810 | 0.894 / 0.883 / 0.810 | |
yunet-s | WIDER FACE val, every 4th image (807), face box AP easy / medium / hard | 0.885 / 0.868 / 0.764 | 0.885 / 0.868 / 0.764 | 0.885 / 0.868 / 0.764 | 0.885 / 0.868 / 0.764 |
Measured on NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks f104019b, 2026-11-14.
Parity
CPU, float32: max |diff| <= 0.001 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.1 and p99 <= 0.3 (absolute error of the output keypoints).
| variant | kernels error vs original, mean / p99 | GPU, torch | kernels used |
|---|---|---|---|
yunet-n | 0.0218 / 0.03939 | 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 |
yunet-s | 0.01636 / 0.03906 | 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; decoding and NMS remain outside the exported graph.
- No per-landmark confidence: keypoint_scores repeats the face score.
- The image is not resized: faces much smaller than about 10 px are missed; large photos cost time in proportion to their pixels.
Example output
No example rendered for this checkpoint yet.