Models · Semantic segmentation
Sapiens2 segmentation
Meta's Sapiens2 (2026): segmentation of human body parts (29 classes such as face, hair, eyeglasses, limbs and clothing). Custom Sapiens2 licence with use restrictions (commercial use allowed, not in the commercial pack).
experimental Fork of facebookresearch/sapiens2@7e5bae8 · backends: portable, kernels
- Paper Sapiens2 ICLR 2026 · first released 24 Apr 2026
Paper 2026 Added in 0.4.0 Evaluated with 0.4.0
Use it
pip install fastforks Lean install with only what this model needs: pip install fastforks-core
from fastforks import segmentation
model = segmentation.load("sapiens2-seg-0.4b") # fastest backend that runs here
result = model("photo.jpg") # logits=True also returns the class scores
# result fields: labels, logits
labels = result.labels # a torch tensor
arrays = result.numpy() # the tensor fields as NumPy arrays: arrays["labels"]
result.backend # what ran: mode, device, dtype
Other ways to run it
- Backend:
segmentation.load("sapiens2-seg-0.4b", mode="kernels") # or "portable", "auto" (default) - Precision:
segmentation.load("sapiens2-seg-0.4b", dtype="float32") # full precision: slower, portable only
fastforks bench sapiens2-seg-0.4b 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 fp32facebookresearch/sapiens2@7e5bae88456a config model (MODELS.build), fp32, TF32 off | fp32 | 479 | 0.29× | 2,181 MiB/3,206 MiB | 4.2 | 0.69 |
| Original (own default)facebookresearch/sapiens2@7e5bae88456a config model under torch.autocast bfloat16 (no authors' flag) | bf16 | 137 | – | 2,670 MiB/3,206 MiB | 4.2 | 0.27 |
| Portable fp32 | fp32 | not measured | – | – | – | – |
| Portable | fp16 | 122 | 1.1× | 1,082 MiB/1,264 MiB | 0.5 | 0.25 |
| Kernels | fp16 | 102 | 1.3× | 1,045 MiB/1,200 MiB | 1.3 | 0.15 |
| Portable + torch.compile | not measured here | – | – | – | – | |
| TensorRT | not measured here | – | – | – | – |
Measured on RTX 5060 Ti 16 GB, torch 2.14.1+cu130, 2026-11-28 to 2026-12-02. 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 | Load / first call (s) | Output vs reference | Input |
|---|---|---|---|---|---|---|---|
| Apple silicon runs on macOS | |||||||
| Apple M1 Pro 16 GB (MLX, fp16) MLX, torch 2.14.1, 2026-11-30 | Portable | fp16 | 996 | 2,399 MiB process | 8.3 / 2.0 | skip | 1024x768 |
| Portable | fp32 | 1614 | 3,599 MiB process | 12.8 / 6.8 | skip | 1024x768 | |
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 unclear
- Code
- LicenseRef-Sapiens2-License LICENSE
- Weights
- other source
- Training data
- Pretraining on Humans-1B (Meta-internal, not released); segmentation fine-tuning on Shutterstock and Goliath body-part annotations (Meta, not released).
- weights: other
- Sapiens2 License (custom, Meta): commercial use allowed, but with use restrictions (no surveillance, biometric identification, deepfakes, inferring sensitive attributes, military use); redistribution must include the licence. https://github.com/facebookresearch/sapiens2/blob/main/LICENSE.md
Our reading of the licences, not legal advice.
Weights
sapiens2_0.4b_seg.safetensors 1.6 GB· hosted on Hugging Facefastforks downloads and checks these files on first use (fastforks download sapiens2-seg-0.4b).
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 % ↑ | images | ms / image |
|---|---|---|---|---|
| Original fp32 | not measured | |||
| Original fp16 | not measured | |||
| Portable fp32 | fp32 | 60.73 | 291 | 468 |
| Portable | fp16 | 60.75 | 291 | 120 |
| Kernels | not measured | |||
The original code was not run on this dataset, so the table cannot show the distance to it.
Any body part counts as person; ground truth = the COCO person masks. Measured on RTX 5060 Ti, torch 2.14.1+cu130, fastforks c0606f892, 2026-11-30.
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.05 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.01 and p99 <= 0.04 (absolute error of the output logits).
| Check | Tolerance | Measured |
|---|---|---|
| CPU fp32, max |diff| | ≤ 0.05 | not recorded |
| cpu_rtol | ≤ 0.004 | not recorded |
| cpu_outliers | ≤ 0.001 | not recorded |
| GPU default dtypes, mean |diff| | ≤ 0.01 | 0.00198 |
| GPU default dtypes, p99 |diff| | ≤ 0.04 | 0.00746 |
Recorded for sapiens2-seg-0.4b on RTX 5060 Ti, torch 2.14.1+cu130, 2026-12-02, with these kernels: sapiens2_opsswiglu
Details
Sapiens2 (Meta 2026) human body-part segmentation: a ViT with RoPE, grouped-query attention and SwiGLU, pretrained on 1 B human images, fine-tuned with a deconvolution head on 29 classes (face, hair, eyeglasses, left / right limbs, clothing, lips, teeth, tongue); 1024 x 768 input, logits at full input resolution.
- Input / output
- Input: one RGB image. Output: per-pixel class labels (logits with
logits=True). - Input size
- any H x W >= 1, resized or padded inside the model; tested up to 3000x4000 (1,461 MiB allocated)
- Outputs
logits- Checkpoint
embed_dim=1024,depth=24,num_heads=16- CUDA kernels
sapiens2_opsswiglu
Limitations
- Custom licence with use restrictions: not in the commercial selection (FASTFORKS_COMMERCIAL_ONLY, commercial ComfyUI pack).
- Every image is resized to 1024 x 768 without keeping the aspect ratio (upstream test protocol); crop to the person first for small people.
- Portable backend, Apple MLX (hand-written network) and fp16 CUDA kernels.
Full reference, generated from the repository
Meta's Sapiens2 (2026): segmentation of human body parts (29 classes such as face, hair, eyeglasses, limbs and clothing). Custom Sapiens2 licence with use restrictions (commercial use allowed, not in the commercial pack).
Commercial use: unclear (treat as no) (weights: other).
| variant | input | backend | time (ms) | peak memory (MiB, allocated / reserved) |
|---|---|---|---|---|
sapiens2-seg-0.4b | COCO val2017 000000003156.jpg (one person) resized to the input size (2048x1536) | original (fp32) original portable kernels | 479 137 122 102 | 2181 / 3206 2670 / 3206 1082 / 1264 1045 / 1200 |
sapiens2-seg-0.4b | COCO val2017 000000003156.jpg (one person) resized to the input size (1024x768) | original (fp32) original portable kernels portable + torch.compile TensorRT fp16 | 477 135 119 98.2 95.0 291 | 2181 / 2598 2672 / 2858 1055 / 1264 1018 / 1180 1044 / 1142 1928 / 1958 |
sapiens2-seg-1b | COCO val2017 000000003156.jpg (one person) resized to the input size (2048x1536) | original (fp32) original portable kernels | 1520 396 333 287 | 6246 / 9664 8766 / 9664 3111 / 3412 3075 / 3206 |
sapiens2-seg-1b | COCO val2017 000000003156.jpg (one person) resized to the input size (1024x768) | original (fp32) original portable kernels portable + torch.compile TensorRT fp16 | 1517 394 331 284 282 403 | 6246 / 6970 8766 / 9316 3084 / 3412 3048 / 3166 3074 / 3148 5974 / 6020 |
Details
- Original code: https://github.com/facebookresearch/sapiens2 at
7e5bae88456a - Code licence: LicenseRef-Sapiens2-License (permissive); files:
LICENSE - Weights licence: other
- Licence evidence: https://huggingface.co/facebook/sapiens2-seg-0.4b/blob/449b3c5335e6722bb94990abdd1aa6e612432f22/README.md (license: other, license_name: sapiens2-license) ; https://github.com/facebookresearch/sapiens2/blob/7e5bae88456ac418ff0e58e74106c9fe192055d4/LICENSE.md
- Training data: Pretraining on Humans-1B (Meta-internal, not released); segmentation fine-tuning on Shutterstock and Goliath body-part annotations (Meta, not released).
- Licence note: Sapiens2 License (custom, Meta): commercial use allowed, but with use restrictions (no surveillance, biometric identification, deepfakes, inferring sensitive attributes, military use); redistribution must include the licence. https://github.com/facebookresearch/sapiens2/blob/main/LICENSE.md
- Kernel libraries:
sapiens2_ops,swiglu - Variants:
sapiens2-seg-0.4b,sapiens2-seg-1b - Outputs: logits; label_set:
goliath-29 - Input size: any H x W >= 1, resized or padded inside the model
- Tested up to (portable, fp16, RTX 5060 Ti 16 GB):
sapiens2-seg-0.4b3000x4000 (1.4 GiB peak allocated, 1.5 reserved);sapiens2-seg-1b3000x4000 (3.4 GiB peak allocated, 3.6 reserved) sapiens2-seg-0.4b1024x768, first call: portable + torch.compile 38 s (cold Inductor cache), TensorRT fp16 47 s (ONNX + engine).sapiens2-seg-1b1024x768, first call: portable + torch.compile 50 s (cold Inductor cache), TensorRT fp16 122 s (ONNX + engine).sapiens2-seg-0.4boriginal (fp32) 2048x1536, original (fp32) 1024x768: facebookresearch/sapiens2@7e5bae88456a config model (MODELS.build), fp32, TF32 offsapiens2-seg-0.4boriginal 2048x1536, original 1024x768: facebookresearch/sapiens2@7e5bae88456a config model under torch.autocast bfloat16 (no authors' flag)sapiens2-seg-1boriginal (fp32) 2048x1536, original (fp32) 1024x768: facebookresearch/sapiens2@7e5bae88456a config model (MODELS.build), fp32, TF32 offsapiens2-seg-1boriginal 2048x1536, original 1024x768: facebookresearch/sapiens2@7e5bae88456a config model under torch.autocast bfloat16 (no authors' flag)sapiens2-seg-0.4bload / first call: original 4.17 s / 0.274 s (2048x1536), portable 0.48 s / 0.251 s (2048x1536), kernels 1.26 s / 0.22 s (1024x768)sapiens2-seg-1bload / first call: original 4.78 s / 0.536 s (2048x1536), portable 1.19 s / 0.455 s (2048x1536), kernels 38.2 s / 0.4 s (1024x768)- Protocol, median of 20 after 3 warm-ups, batch 1, labels (argmax at the image size); upstream: config test_pipeline + data_preprocessor on the host (not timed), then the network + resize on the GPU; fastforks: float CUDA image in, its own resize on the GPU; peak = one call after the warm-ups (weights included); load / first call: per process (first call at 1024x768)
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 | portable | portable fp32 | note |
|---|---|---|---|---|
sapiens2-seg-0.4b | COCO val2017 persons, every 10th image, person IoU % | 60.75 | 60.73 | |
sapiens2-seg-1b | COCO val2017 persons, every 10th image, person IoU % | 64.87 | 64.88 |
Measured on NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks c0606f892, 2026-11-30.
Parity
CPU, float32: max |diff| <= 0.05 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.01 and p99 <= 0.04 (absolute error of the output logits).
| variant | kernels error vs original, mean / p99 | GPU, torch | kernels used |
|---|---|---|---|
sapiens2-seg-0.4b | 0.00198 / 0.00746 | RTX 5060 Ti, torch 2.14.1+cu130 | sapiens2_ops@20cfca7e340c:sm_120, swiglu@25fe34a2d389:sm_120 |
sapiens2-seg-1b | 0.00149 / 0.00556 | RTX 5060 Ti, torch 2.14.1+cu130 | sapiens2_ops@20cfca7e340c:sm_120, swiglu@25fe34a2d389:sm_120 |
Limitations
- Custom licence with use restrictions: not in the commercial selection (FASTFORKS_COMMERCIAL_ONLY, commercial ComfyUI pack).
- Every image is resized to 1024 x 768 without keeping the aspect ratio (upstream test protocol); crop to the person first for small people.
- Portable backend, Apple MLX (hand-written network) and fp16 CUDA kernels.
Example output
No example rendered for this checkpoint yet.