Sapiens2 segmentation (fastforks)

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.

This repo is the model card only: it holds no weights. fastforks downloads the authors' weights from the links below and checks them against the SHA-256 in the model card. Code: https://github.com/kleinicke/fastforks. Kernels for the kernels backend: https://huggingface.co/fastforks/kernels. Original code: https://github.com/facebookresearch/sapiens2 at 7e5bae88456a.

Author weight repos: https://huggingface.co/facebook/sapiens2-seg-0.4b, https://huggingface.co/facebook/sapiens2-seg-1b.

Task: segmentation. Tier: experimental. Outputs: logits. Backends: portable, kernels.

Input: one RGB image. Output: per-pixel class labels (logits with logits=True).

Variants

Weights are the authors' files (not hosted here). SHA-256 shortened to 12 hex digits; the full hashes are in card.toml.

variant weights (author link) SHA-256 weights licence commercial use
sapiens2-seg-0.4b@1 sapiens2_0.4b_seg.safetensors b85fdb50b7d6 other unclear (treat as no)
sapiens2-seg-1b@1 sapiens2_1b_seg.safetensors 4b73c44963b3 other unclear (treat as no)

Licence

Original-code strings, recorded as they are (research-use package; check them before any other use). Code: LicenseRef-Sapiens2-License. Licence files: LICENSE.

Training data: Pretraining on Humans-1B (Meta-internal, not released); segmentation fine-tuning on Shutterstock and Goliath body-part annotations (Meta, not released)..

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

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)

Speed and memory

Segmentation, synthetic

model input time (ms): original fp32 original portable kernels kernels speed-up: vs original vs portable peak memory (MiB, allocated / reserved): original portable kernels
sapiens2-seg-0.4b 2048x1536 – – – 102 – – – – 1045 / 1200
sapiens2-seg-1b 2048x1536 – – – 287 – – – – 3075 / 3206

Segmentation, COCO val2017 000000003156.jpg (one person) resized to the input size, 2048x1536

model time (ms): original fp32 original portable peak memory (MiB, allocated / reserved): original portable
sapiens2-seg-0.4b 479 137 122 2670 / 3206 1082 / 1264
sapiens2-seg-1b 1520 396 333 8766 / 9664 3111 / 3412

Startup and first call

model load (s): original portable kernels first call (s): original portable kernels
sapiens2-seg-0.4b 4.17 (2048x1536) 0.48 (2048x1536) 1.26 (1024x768) 0.27 (2048x1536) 0.25 (2048x1536) 0.22 (1024x768)
sapiens2-seg-1b 4.78 (2048x1536) 1.19 (2048x1536) 38.20 (1024x768) 0.54 (2048x1536) 0.46 (2048x1536) 0.40 (1024x768)

torch.compile and TensorRT

model input time: portable compile TensorRT (fp16 unless shown) kernels preparation: compile (cold first call) ONNX + engine build peak MiB (alloc / reserved): portable compile kernels TensorRT (engine + torch)
sapiens2-seg-0.4b 1024x768 119 ms 95.0 ms 291 ms 98.2 ms 37.8 s 47.4 s 1055 / 1264 1044 / 1142 1018 / 1180 1928 / 1958
sapiens2-seg-1b 1024x768 331 ms 282 ms 403 ms 284 ms 50.5 s 122 s 3084 / 3412 3074 / 3148 3048 / 3166 5974 / 6020

Fixed-size cells: time (ms) / peak allocated / peak reserved memory (MiB).

Hardware, protocol and caveats: benchmarks (RTX 5060 Ti 16 GB, sm_120). Original = the original code named above at the precision of portable (fp16, or (fp32) where fp16 is unsupported or not finite); original fp32 = its default fp32 run. Peak memory is the torch allocator's.

Accuracy

On public datasets

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 with the original code

Every variant is checked against reference outputs of the original code at its pinned commit. 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).

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.

Usage

from fastforks import segmentation

model = segmentation.load("sapiens2-seg-0.4b")  # mode="auto": the preferred backend from recorded measurements
result = model("photo.jpg")
result.labels  # [H, W] per-pixel class index
result.backend  # what ran, e.g. Backend(mode='portable', device='cuda:0', dtype='float16')

Install with pip install fastforks (see https://github.com/kleinicke/fastforks). Other variants: sapiens2-seg-0.4b, sapiens2-seg-1b.

Kernels backend

segmentation.load("sapiens2-seg-0.4b", mode="kernels") runs our CUDA kernels (sapiens2_ops, swiglu). It needs a prebuilt kernel for your GPU architecture (downloaded from https://huggingface.co/fastforks/kernels on first use) and a recent NVIDIA driver; if there is none it raises BackendUnavailableError with the reason and never falls back silently. mode="auto" picks kernels when it can run and logs the choice.

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Model tree for fastforks/sapiens2

Finetuned
(4)
this model