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
Checkpoint

Paper 2026 Added in 0.4.0 Evaluated with 0.4.0

Kernels, RTX 5060 Ti 16 GB 102 ms 2048x1536, fp16
vs the faster original 1.3× original bf16: 137 ms
Peak memory 1,045 MiB original: 2,670 MiB
Accuracy vs original fp32 – original not run on the test set

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.

BackenddtypeTime per call (ms)vs original fp16Peak memory
allocated / reserved
Load (s)First call (s)
Original fp32facebookresearch/sapiens2@7e5bae88456a config model (MODELS.build), fp32, TF32 offfp32 4790.29×2,181 MiB/3,206 MiB4.20.69
Original (own default)facebookresearch/sapiens2@7e5bae88456a config model under torch.autocast bfloat16 (no authors' flag)bf16 137–2,670 MiB/3,206 MiB4.20.27
Portable fp32fp32not measured ––––
Portablefp16 1221.1×1,082 MiB/1,264 MiB0.50.25
Kernelsfp16 1021.3×1,045 MiB/1,200 MiB1.30.15
Portable + torch.compilenot measured here ––––
TensorRTnot 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

DeviceBackenddtypems / callPeak memoryLoad / first call (s)Output vs referenceInput
Apple silicon runs on macOS
Apple M1 Pro 16 GB (MLX, fp16) MLX, torch 2.14.1, 2026-11-30Portablefp16996 2,399 MiB process8.3 / 2.0skip1024x768
Portablefp321614 3,599 MiB process12.8 / 6.8skip1024x768

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 Face

fastforks 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 %

Rundtypeperson IoU % ↑imagesms / image
Original fp32not measured
Original fp16not measured
Portable fp32fp3260.73 291 468
Portablefp1660.75 291 120
Kernelsnot 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).

CheckToleranceMeasured
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_ops
  • swiglu

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).

variantinputbackendtime (ms)peak memory (MiB, allocated / reserved)
sapiens2-seg-0.4bCOCO 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.4bCOCO 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-1bCOCO 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-1bCOCO 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.4b 3000x4000 (1.4 GiB peak allocated, 1.5 reserved); sapiens2-seg-1b 3000x4000 (3.4 GiB peak allocated, 3.6 reserved)
  • sapiens2-seg-0.4b 1024x768, first call: portable + torch.compile 38 s (cold Inductor cache), TensorRT fp16 47 s (ONNX + engine).
  • sapiens2-seg-1b 1024x768, first call: portable + torch.compile 50 s (cold Inductor cache), TensorRT fp16 122 s (ONNX + engine).
  • sapiens2-seg-0.4b original (fp32) 2048x1536, original (fp32) 1024x768: facebookresearch/sapiens2@7e5bae88456a config model (MODELS.build), fp32, TF32 off
  • sapiens2-seg-0.4b original 2048x1536, original 1024x768: facebookresearch/sapiens2@7e5bae88456a config model under torch.autocast bfloat16 (no authors' flag)
  • sapiens2-seg-1b original (fp32) 2048x1536, original (fp32) 1024x768: facebookresearch/sapiens2@7e5bae88456a config model (MODELS.build), fp32, TF32 off
  • sapiens2-seg-1b original 2048x1536, original 1024x768: facebookresearch/sapiens2@7e5bae88456a config model under torch.autocast bfloat16 (no authors' flag)
  • sapiens2-seg-0.4b load / 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-1b load / 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.

variantdatasetportableportable fp32note
sapiens2-seg-0.4bCOCO val2017 persons, every 10th image, person IoU %60.7560.73
sapiens2-seg-1bCOCO val2017 persons, every 10th image, person IoU %64.8764.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).

variantkernels error vs original, mean / p99GPU, torchkernels used
sapiens2-seg-0.4b0.00198 / 0.00746RTX 5060 Ti, torch 2.14.1+cu130sapiens2_ops@20cfca7e340c:sm_120, swiglu@25fe34a2d389:sm_120
sapiens2-seg-1b0.00149 / 0.00556RTX 5060 Ti, torch 2.14.1+cu130sapiens2_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.