Models · Semantic segmentation
Sapiens segmentation
Meta's Sapiens: segmentation of human body parts (28 Goliath classes such as face, hair, limbs and clothing). Non-commercial licence.
stable Fork of facebookresearch/sapiens@2cb0722 · backends: portable, kernels
- Paper Sapiens: Foundation for Human Vision Models ECCV 2024 (oral) · first released 22 Aug 2024
Paper 2024 Added in 0.1.0 Evaluated with 0.2.0
Use it
pip install fastforks Lean install with only what this model needs: pip install "fastforks-core[nc]"
from fastforks import segmentation
model = segmentation.load("sapiens-seg-0.3b-goliath") # kernels on a supported GPU, else portable PyTorch
result = model(image)
result.logits
result.backend # what ran: mode, device, dtype, kernels The weights are non-commercial: fastforks downloads them only with FASTFORKS_NONCOMMERCIAL=1 set.
fastforks bench sapiens-seg-0.3b-goliath 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.
| Backend | dtype | Time per call (ms) | vs original fp16 | Peak memory allocated / reserved | Load (s) | First call (s) |
|---|---|---|---|---|---|---|
| Original fp32 | fp32 | 466 | 0.37× | 3,673 MiB/4,104 MiB | – | – |
| Original fp16torch.autocast(fp16) around the forward | fp16 | 173 | – | 2,520 MiB/2,724 MiB | – | – |
| Portable fp32 | fp32 | not measured | – | – | – | – |
| Portable | fp16 | 132 | 1.3× | 1,643 MiB/1,762 MiB | 1.2 | 0.13 |
| Kernels | fp16 | 92.6 | 1.9× | 1,643 MiB/1,762 MiB | 1.0 | 0.09 |
| Portable + torch.compile | 118 | 1.5× | 1,373 MiB/1,462 MiB | 12 (build) | – | |
| TensorRT fp16 | fp16 | 156 | 1.1× | 1,564 MiBenginenot comparable | 53 (build) | – |
Measured on RTX 5060 Ti 16 GB, torch 2.14.1+cu130, 2026-11-03 to 2026-11-04. First call, 3 warm-up, peak reset, median of 3 rounds x median of 5 (tools/speed_check.py), synthetic CUDA input (bench_inputs); peak = max over the first call and the timed calls. 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-12 | Original | fp32 | 4354 | 4,741 MiB process | matches | 1024x2048 |
| Portable | fp16 | 1517 | 3,748 MiB process | matches | 1024x2048 | |
| Portable | fp32 | 2988 | 4,766 MiB process | matches | 1024x2048 | |
| Kernels | fp16 | not implemented | – | 1024x2048 | ||
| NVIDIA L4 CUDA, torch 2.14.1+cu130, 2026-11-07 | Portable | fp16 | 142 | 1,616 MiB/1,742 MiB | – | 1024x2048 |
| Kernels | fp16 | 135 | 1,628 MiB/1,742 MiB | – | 1024x2048 | |
| NVIDIA L40S CUDA, torch 2.14.1+cu130, 2026-11-07 | Portable | fp16 | 40.9 | 1,754 MiB/1,882 MiB | – | 1024x2048 |
| Kernels | fp16 | 39.7 | 1,766 MiB/1,882 MiB | – | 1024x2048 | |
| NVIDIA A10 CUDA, torch 2.14.1+cu130, 2026-11-07 | Portable | fp16 | 99.3 | 1,616 MiB/1,742 MiB | – | 1024x2048 |
| Kernels | fp16 | 97.7 | 1,616 MiB/1,742 MiB | – | 1024x2048 | |
| NVIDIA A100-SXM4-40GB CUDA, torch 2.14.1+cu130, 2026-11-08 | Portable | fp16 | 36.3 | 1,760 MiB/1,882 MiB | – | 1024x2048 |
| Kernels | fp16 | 34.4 | 1,760 MiB/1,882 MiB | – | 1024x2048 | |
| NVIDIA RTX PRO 6000 CUDA, torch 2.14.1+cu130, 2026-11-08 | Portable | fp16 | 24.4 | 1,916 MiB/2,042 MiB | – | 1024x2048 |
| Kernels | fp16 | 25.7 | 1,916 MiB/2,042 MiB | – | 1024x2048 | |
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
Non-commercial only
- Code
- CC-BY-NC-4.0 LICENSE
- Weights
- CC-BY-NC-4.0 source
- Training data
- MAE pretraining on Humans-300M (Meta-internal, not released); segmentation fine-tuning on Goliath body-part annotations (Meta, not released)
- code: CC-BY-NC-4.0 (noncommercial)
- weights: CC-BY-NC-4.0
Our reading of the licences, not legal advice.
Weights
sapiens_0.3b_goliath_best_goliath_mIoU_7673_epoch_194_torchscript.pt2 1.4 GB· hosted on Hugging Facefastforks downloads and checks these files on first use (fastforks download sapiens-seg-0.3b-goliath). Non-commercial weights need FASTFORKS_NONCOMMERCIAL=1.
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.
COCO val2017 persons
every 10th image, person IoU %
| Run | dtype | person IoU % ↑ | Δ person IoU % vs fp32 original | images | ms / image |
|---|---|---|---|---|---|
| Original fp32 | fp32 | 32.60 | reference | 291 | 469 |
| Original fp16 | fp16 | 32.61 | +0.01 | 291 | 179 |
| Portable fp32 | fp32 | 32.60 | ±0.00 | 291 | 445 |
| Portable | fp16 | 32.61 | +0.01 | 291 | 132 |
| Kernels | fp16 | 32.62 | +0.02 | 291 | 92.0 |
Any body part counts as person; ground truth = the COCO person masks. Original = the authors’ code, same checkpoint and protocol. Measured on original fp32, original fp16: RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-06; portable fp32: RTX 5060 Ti, torch 2.14.1+cu130, fastforks 44640884, 2026-11-17; portable, kernels: RTX 5060 Ti, torch 2.14.1+cu130, fastforks 939adfe8, 2026-11-06.
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.002 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.05 and p99 <= 0.25 (absolute error of the output logits).
| Check | Tolerance | Measured |
|---|---|---|
| CPU fp32, max |diff| | ≤ 0.002 | not recorded |
| GPU default dtypes, mean |diff| | ≤ 0.05 | 0.00478 |
| GPU default dtypes, p99 |diff| | ≤ 0.25 | 0.01673 |
Recorded for sapiens-seg-0.3b-goliath on RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-04, with these kernels: cudnn_haccfastbbseg_up
Details
Sapiens (Khirodkar et al. 2024) human body-part segmentation: a ViT pretrained on 300 M human images, fine-tuned with a deconvolution head on Goliath's 28 classes (face, hair, left / right limbs, clothing, lips, teeth, ...); 1024 x 768 input, the Sapiens-Lite TorchScript checkpoints.
- Input / output
- Input: one RGB image. Output: per-pixel class labels (logits with
logits=True). - Input size
- any H x W >= 32, padded to a multiple of 32; tested up to 3000x4000 (2,254 MiB allocated)
- Outputs
logits- Checkpoint
embed_dim=1024,depth=24,num_heads=16- CUDA kernels
fastbbfast backbone kernels: flash attention, window attention, instance norm and rotary embeddings for ViT and similar backbonescudnn_haccconvolutions with fp16 accumulation (cuDNN)seg_upfused resize and argmax of segmentation scores
- Apple (MPS)
- fp32, fp16
Full reference, generated from the repository
Meta's Sapiens: segmentation of human body parts (28 Goliath classes such as face, hair, limbs and clothing). Non-commercial licence.
Commercial use: no (code: CC-BY-NC-4.0 (noncommercial); weights: CC-BY-NC-4.0).
| variant | input | backend | time (ms) | peak memory (MiB, allocated / reserved) |
|---|---|---|---|---|
sapiens-seg-0.3b-goliath | synthetic (1024x2048) | original (fp32) original portable kernels portable + torch.compile TensorRT fp16 | 466 173 132 92.6 118 156 | 3673 / 4104 2520 / 2724 1643 / 1762 1643 / 1762 1373 / 1462 2465 / 2526 |
sapiens-seg-1b-goliath | synthetic (1024x2048) | original (fp32) original portable kernels portable + torch.compile TensorRT fp16 | 1189 354 275 185 263 244 | 6874 / 7284 5721 / 5906 3259 / 3384 3259 / 3382 2986 / 3084 5694 / 5742 |
Details
- Original code: https://github.com/facebookresearch/sapiens at
2cb07227a740 - Code licence: CC-BY-NC-4.0 (noncommercial); files:
LICENSE - Weights licence: CC-BY-NC-4.0
- Licence evidence: https://huggingface.co/facebook/sapiens-seg-1b-torchscript/blob/584504252a6d2a27ea6560927811db734ee42332/README.md
- Training data: MAE pretraining on Humans-300M (Meta-internal, not released); segmentation fine-tuning on Goliath body-part annotations (Meta, not released)
- Kernel libraries:
fastbb,cudnn_hacc,seg_up - Variants:
sapiens-seg-0.3b-goliath,sapiens-seg-1b-goliath - Outputs: logits; label_set:
goliath-28 - Input size: any H x W >= 32, padded to a multiple of 32
- Tested up to (portable, fp16, RTX 5060 Ti 16 GB):
sapiens-seg-0.3b-goliath3000x4000 (2.2 GiB peak allocated, 3.2 reserved);sapiens-seg-1b-goliath3000x4000 (3.8 GiB peak allocated, 5.0 reserved) sapiens-seg-0.3b-goliath1024x2048, first call: portable + torch.compile 12 s (cold Inductor cache), TensorRT fp16 53 s (ONNX + engine).sapiens-seg-1b-goliath1024x2048, first call: portable + torch.compile 19 s (cold Inductor cache), TensorRT fp16 85 s (ONNX + engine).sapiens-seg-0.3b-goliathoriginal 1024x2048: torch.autocast(fp16) around the forwardsapiens-seg-1b-goliathoriginal 1024x2048: torch.autocast(fp16) around the forwardsapiens-seg-0.3b-goliathload / first call: original 4.92 s / 1.024 s (512x512), portable 1.22 s / 0.132† s, kernels 0.96† s / 0.092† ssapiens-seg-1b-goliathload / first call: original 11.33 s / 0.569 s (512x512), portable 3.54 s / 0.274† s, kernels 2.27† s / 0.18† s- † measured in the speed sweep after the portable load (or an earlier size) in the same process: file cache and kernels are warm, so the time is lower than a fresh start.
- Protocol, first call, 3 warm-up, peak reset, median of 3 rounds x median of 5 (tools/speed_check.py), synthetic CUDA input (bench_inputs); peak = max over the first call and the timed calls
Measured
Any body part counts as person; ground truth = the COCO person masks. Original = the original code named under Details, same checkpoint and protocol.
| variant | dataset | original fp32 | original fp16 | portable | portable fp32 | kernels | note |
|---|---|---|---|---|---|---|---|
sapiens-seg-0.3b-goliath | COCO val2017 persons, every 10th image, person IoU % | 32.60 | 32.61 | 32.61 | 32.60 | 32.62 | |
sapiens-seg-1b-goliath | COCO val2017 persons, every 10th image, person IoU % | 54.22 | 54.22 | 54.22 | 54.19 |
Measured on portable: NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 939adfe8, 2026-11-06; portable32: NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 44640884, 2026-11-17; kernels: NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 939adfe8, 2026-11-06.
Parity
CPU, float32: max |diff| <= 0.002 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.05 and p99 <= 0.25 (absolute error of the output logits).
| variant | kernels error vs original, mean / p99 | GPU, torch | kernels used |
|---|---|---|---|
sapiens-seg-0.3b-goliath | 0.00478 / 0.01673 | RTX 5060 Ti, torch 2.14.1+cu130 | cudnn_hacc@cudnn92400, fastbb@7d058322634d:sm_120, seg_up@3e44e71200cd:sm_120 |
sapiens-seg-1b-goliath | 0.00819 / 0.03064 | RTX 5060 Ti, torch 2.14.1+cu130 | cudnn_hacc@cudnn92400, fastbb@7d058322634d:sm_120, seg_up@3e44e71200cd:sm_120 |
Example output
One fixed input through this checkpoint, the same for every model of the task (kernels · float16 · NVIDIA GeForce RTX 5060 Ti).
- Background 100%
Input: A cup of coffee, Rachel Michetti (CC0).