ViTMatte (fastforks)

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

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/hustvl/ViTMatte at 8cd7ef068380.

Author weight repos: https://huggingface.co/hustvl/vitmatte-base-composition-1k, https://huggingface.co/hustvl/vitmatte-small-composition-1k.

Task: matting. Tier: experimental. Outputs: alpha. Backends: portable, kernels.

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

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
vitmatte-b@1 vitmatte-b-composition-1k.bin b2521bcc4b71 Apache-2.0 yes
vitmatte-s@1 vitmatte-s-composition-1k.safetensors bda9289db1bb Apache-2.0 yes

Licence

Original-code strings, recorded as they are (research-use package; check them before any other use). Code: Apache-2.0. Licence files: 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.).

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

Input size

any H x W >= 32, padded to a multiple of 32 Tested up to (portable, fp16, RTX 5060 Ti 16 GB): vitmatte-b 3000x4000 (8.0 GiB peak allocated, 14.3 reserved); vitmatte-s 3000x4000 (7.8 GiB peak allocated, 13.9 reserved)

Speed and memory

Matting, synthetic, 1080x1920

model time (ms): original portable kernels kernels speed-up: vs original vs portable peak memory (MiB, allocated / reserved): original portable kernels
vitmatte-b 257 182 148 1.7x 1.2x 5070 / 5128 1548 / 1692 1452 / 1552
vitmatte-s 140 102 84.1 1.7x 1.2x 2536 / 2582 1401 / 1524 1305 / 1404

Startup and first call

model load (s): original portable kernels first call (s): original portable kernels
vitmatte-b 0.21 0.52 1.32 0.56 0.35 0.25
vitmatte-s 2.85 0.16 1.30 0.72 0.41 0.20

torch.compile and TensorRT

model input time: portable compile TensorRT fp16 kernels preparation: compile (cold first call) ONNX + engine build peak MiB (alloc / reserved): portable compile kernels TensorRT (engine + torch)
vitmatte-b 1080x1920 182 ms 157 ms 108 ms 148 ms 32.6 s 48.8 s 1548 / 1692 1166 / 1472 1452 / 1552 1233 / 1262
vitmatte-s 1080x1920 102 ms 81.9 ms 54.6 ms 84.1 ms 31.5 s 51.3 s 1401 / 1524 1025 / 1284 1305 / 1404 876 / 920

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

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.

variant dataset original fp32 original fp16 portable kernels note
vitmatte-s AIM-500, every 5th image (100), generated trimaps, SAD / MSE x 1000 (unknown region) 13.86 / 11.727 13.85 / 11.727 13.85 / 11.726 13.85 / 11.723
vitmatte-b AIM-500, all 500 images, generated trimaps, SAD / MSE x 1000 (unknown region) 13.72 / 12.180
vitmatte-b AIM-500, every 5th image (100), generated trimaps, SAD / MSE x 1000 (unknown region) 16.39 / 13.937 16.40 / 13.936 16.40 / 13.936 16.39 / 13.938

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

Parity with the original code

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

Usage

from fastforks import matting

model = matting.load("vitmatte-b")  # mode="auto": the preferred backend from recorded measurements
result = model("photo.jpg")
result.alpha  # [H, W] float32 in [0, 1], input resolution
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: vitmatte-b, vitmatte-s.

Kernels backend

matting.load("vitmatte-b", mode="kernels") runs our CUDA kernels (dpt_fused, cudnn_hacc, igev, cutlass_conv). 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/vitmatte

Finetuned
(2)
this model

Collection including fastforks/vitmatte