Models · Matting

ViTMatte

ViTMatte (Huazhong University of Science and Technology, 2023): refines a rough trimap (sure background, sure foreground, unknown band) into a soft alpha matte, e.g. hair and fur edges; a plain Vision Transformer plus a small detail decoder; small and base versions. Apache-2.0 code and weights.

experimental Fork of hustvl/ViTMatte@8cd7ef0 · backends: portable, kernels

Checkpoint

Paper 2023 Added in 0.2.0 Evaluated with 0.2.0

Kernels, RTX 5060 Ti 16 GB 84.1 ms 1080x1920, fp16
vs the faster original 1.7× original fp16: 140 ms
Peak memory 1,305 MiB original: 2,536 MiB
Accuracy vs original fp32 −0.01 kernels sad, AIM-500 (13.86 original)

Use it

pip install fastforks

Lean install with only what this model needs: pip install fastforks-core

from fastforks import matting

model = matting.load("vitmatte-s")  # kernels on a supported GPU, else portable PyTorch
result = model(image)
result.alpha
result.backend  # what ran: mode, device, dtype, kernels
fastforks bench vitmatte-s

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)

BackenddtypeTime per call (ms)vs original fp16Peak memory
allocated / reserved
Load (s)First call (s)
Original fp32fp32not measured ––––
Original fp16the authors' mixed-precision option (float16); transformers 5.19.0 VitMatteForImageMatting, normalise / trimap / pad 32 / cropfp16 140–2,536 MiB/2,582 MiB0.10.39
Portable fp32fp32not measured ––––
Portablefp16 1021.4×1,401 MiB/1,524 MiB0.20.41
Kernelsfp16 84.11.7×1,305 MiB/1,404 MiB0.80.35
Portable + torch.compile 81.91.7×1,025 MiB/1,284 MiB31 (build)–
TensorRT fp16fp16 54.62.6×696 MiBenginenot comparable51 (build)–

Measured on RTX 5060 Ti 16 GB, torch 2.14.1+cu130, 2026-11-12 to 2026-11-15. 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 memoryOutput vs referenceInput
Apple M1 Pro 16 GB MPS, torch 2.14.1, 2026-11-14Originalfp323605 9,787 MiB process–1080x1920
Portablefp161360 2,542 MiB processmatches1080x1920
Portablefp322333 5,185 MiB processmatches1080x1920
Kernelsfp16not 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
Apache-2.0 LICENSE
Weights
Apache-2.0 source
Training data

Our reading of the licences, not legal advice.

Weights

vitmatte-s-composition-1k.safetensors 103 MB· hosted on Hugging Face

fastforks downloads and checks these files on first use (fastforks download vitmatte-s).

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.

AIM-500

every 5th image (100), generated trimaps, SAD / MSE x 1000 (unknown region)

Rundtypesad ↑mse ↑Δ sad vs fp32 originalimagesms / image
Original fp32fp3213.8611.727 reference 100 215
Original fp16fp1613.8511.727 −0.01 100 110
Portable fp32fp3213.8611.727 ±0.00 100 293
Portablefp1613.8511.726 −0.01 100 85.3
Kernelsfp1613.8511.723 −0.01 100 70.2

Trimap-guided models, AIM-500: each image at its own size with a trimap made from its alpha (alpha 255 / 0 eroded by a 21 px ellipse = foreground / background, the rest unknown); SAD / 1000 and MSE of the 8-bit alpha in the unknown region (ViTMatte's evaluation). Original = the authors’ code, same checkpoint and protocol. Measured on original fp32, original fp16: RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-12; portable fp32, portable, kernels: RTX 5060 Ti, torch 2.14.1+cu130, fastforks 4068530d, 2026-11-12.

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| <= 5.8e-06 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 5.3e-05 and p99 <= 0.0012 (absolute error of the output alpha).

CheckToleranceMeasured
CPU fp32, max |diff|≤ 0.0000058 not recorded
GPU default dtypes, mean |diff|≤ 0.000053 0.00003
GPU default dtypes, p99 |diff|≤ 0.0012 0.0007

Recorded for vitmatte-s on RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-12, with these kernels: cudnn_hacccutlass_convdpt_fusedigev

Details

ViTMatte (Yao et al., HUST, Information Fusion 2024): trimap-based natural image matting. A plain ViT (ViTDet: windowed attention with relative positions plus four global blocks with convolutional residual blocks) sees the image and its trimap as one 4-channel input; a light convolutional detail-capture decoder fuses the ViT features with a full-resolution conv stream into the alpha. Needs a trimap (0 background, 128 unknown, 255 foreground).

Input / output
Input: one RGB image (trimap-guided models also a trimap: background / unknown / foreground). Output: an alpha matte [H, W] in [0, 1] at the input size: 1 = foreground (background removal, dichotomous / salient object segmentation).
Input size
any H x W >= 32, padded to a multiple of 32; tested up to 3000x4000 (7,954 MiB allocated)
Outputs
alpha
CUDA kernels
  • dpt_fusedfused fp16 matrix multiplies and convolutions for DINOv2 backbones and DPT depth heads
  • cudnn_haccconvolutions with fp16 accumulation (cuDNN)
  • igevIGEV stereo: convolution epilogues, correlation lookups, GRU gates
  • cutlass_convCUTLASS convolutions with the recurrent update (GRU) fused in
Apple (MPS)
fp32, fp16
Full reference, generated from the repository

ViTMatte (Huazhong University of Science and Technology, 2023): refines a rough trimap (sure background, sure foreground, unknown band) into a soft alpha matte, e.g. hair and fur edges; a plain Vision Transformer plus a small detail decoder; small and base versions. Apache-2.0 code and weights.

Commercial use: yes.

variantinputbackendtime (ms)peak memory (MiB, allocated / reserved)
vitmatte-ssynthetic (1080x1920)original
portable
kernels
portable + torch.compile
TensorRT fp16
140
102
84.1
81.9
54.6
2536 / 2582
1401 / 1524
1305 / 1404
1025 / 1284
876 / 920
vitmatte-bsynthetic (1080x1920)original
portable
kernels
portable + torch.compile
TensorRT fp16
257
182
148
157
108
5070 / 5128
1548 / 1692
1452 / 1552
1166 / 1472
1233 / 1262
Details
  • Original code: https://github.com/hustvl/ViTMatte at 8cd7ef068380
  • Code licence: Apache-2.0 (permissive); files: LICENSE
  • Weights licence: Apache-2.0
  • Licence evidence: https://huggingface.co/hustvl/vitmatte-small-composition-1k/blob/6a58ad7646403c1df626fbd746900aec7361ea1d/README.md ; https://huggingface.co/hustvl/vitmatte-base-composition-1k/blob/bf486d01a7d9e3dbcc8400f7942835caf0eaf76e/README.md ; https://github.com/hustvl/ViTMatte/blob/8cd7ef068380977c3962c4cb733cb1fe7f2241a5/LICENSE
  • Training data: Composition-1k (Adobe Deep Image Matting) (The HF cards: "ViTMatte model trained on Composition-1k". Adobe Deep Image Matting (Composition-1k) is released for non-commercial research on request; only the weights licence (Apache-2.0) counts for the commercial flag.)
  • Kernel libraries: dpt_fused, cudnn_hacc, igev, cutlass_conv
  • Variants: vitmatte-s, vitmatte-b
  • Outputs: alpha
  • Input size: any H x W >= 32, padded to a multiple of 32
  • Tested up to (portable, fp16, RTX 5060 Ti 16 GB): vitmatte-s 3000x4000 (7.8 GiB peak allocated, 13.9 reserved); vitmatte-b 3000x4000 (8.0 GiB peak allocated, 14.3 reserved)
  • vitmatte-s 1080x1920, first call: portable + torch.compile 31 s (cold Inductor cache), TensorRT fp16 51 s (ONNX + engine).
  • vitmatte-b 1080x1920, first call: portable + torch.compile 33 s (cold Inductor cache), TensorRT fp16 49 s (ONNX + engine).
  • vitmatte-s original 1080x1920: the authors' mixed-precision option (float16); transformers 5.19.0 VitMatteForImageMatting, normalise / trimap / pad 32 / crop
  • vitmatte-b original 1080x1920: the authors' mixed-precision option (float16); transformers 5.19.0 VitMatteForImageMatting, normalise / trimap / pad 32 / crop
  • vitmatte-s load / first call: original 2.85 s / 0.722 s, portable 0.16 s / 0.413 s, kernels 1.3 s / 0.202 s
  • vitmatte-b load / first call: original 0.21 s / 0.562 s, portable 0.52 s / 0.35 s, kernels 1.32 s / 0.249 s
  • Protocol, first call, 3 warm-up, peak reset, median of 3 rounds x median of 5

Measured

Trimap-guided models, AIM-500: each image at its own size with a trimap made from its alpha (alpha 255 / 0 eroded by a 21 px ellipse = foreground / background, the rest unknown); SAD / 1000 and MSE of the 8-bit alpha in the unknown region (ViTMatte's evaluation). Original = the original code named under Details, same checkpoint and protocol.

variantdatasetoriginal fp32original fp16portableportable fp32kernelsnote
vitmatte-sAIM-500, every 5th image (100), generated trimaps, SAD / MSE x 1000 (unknown region)13.86 / 11.72713.85 / 11.72713.85 / 11.72613.86 / 11.72713.85 / 11.723
vitmatte-bAIM-500, all 500 images, generated trimaps, SAD / MSE x 1000 (unknown region)13.72 / 12.180
vitmatte-bAIM-500, every 5th image (100), generated trimaps, SAD / MSE x 1000 (unknown region)16.39 / 13.93716.40 / 13.93616.40 / 13.93616.39 / 13.93716.39 / 13.938

Measured on NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 4068530d, 2026-11-12.

Parity

CPU, float32: max |diff| <= 5.8e-06 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 5.3e-05 and p99 <= 0.0012 (absolute error of the output alpha).

variantkernels error vs original, mean / p99GPU, torchkernels used
vitmatte-s3e-05 / 0.0007RTX 5060 Ti, torch 2.14.1+cu130cudnn_hacc@cudnn92400, cutlass_conv@988138e042cb:sm_120, dpt_fused@48e0065bb7cf:sm_120, igev@f075827d68c6:sm_120
vitmatte-b3e-05 / 0.00064RTX 5060 Ti, torch 2.14.1+cu130cudnn_hacc@cudnn92400, cutlass_conv@988138e042cb:sm_120, dpt_fused@48e0065bb7cf:sm_120, igev@f075827d68c6:sm_120

Example output

No example rendered for this checkpoint yet.