MatAnyone (fastforks)

MatAnyone (Yang et al., NTU S-Lab, CVPR 2025): video matting of one object from a mask on the first frame. A Cutie-style memory network (ResNet-50 frame encoder, ResNet-18 mask encoder, object transformer) reads the alpha and features of earlier frames with consistent memory propagation: each region updates its memory only where the alpha changes. Takes a video and the first-frame mask (video); a single image is a one-frame video.

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/pq-yang/MatAnyone at e5ddc534c1ff.

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

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
matanyone@1 matanyone.pth dd26b991d020 LicenseRef-noncommercial no

Licence

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

Training data: VM800 (MatAnyone video matting foregrounds), Composition-1k (Adobe Deep Image Matting), Distinctions-646 (image matting), BG-20k (background images), DVM background set (video backgrounds), COCO 2017 (train, instance annotations), YouTube-VIS 2021 (video instance segmentation), Supervisely Person Dataset (human segmentation) (doc/TRAIN.md: matting on VM800 (not released) and ImageMatte (Distinctions-646 + Adobe Image Matting), backgrounds from BG-20k and DVM, segmentation on COCO, YouTube-VIS 2021 and Supervisely Person.).

Licence evidence: https://github.com/pq-yang/MatAnyone/blob/e5ddc534c1fff9bb9e54cf476095d29071b7cb4f/LICENSE ; https://github.com/pq-yang/MatAnyone/blob/e5ddc534c1fff9bb9e54cf476095d29071b7cb4f/README.md (weights: https://github.com/pq-yang/MatAnyone/releases/tag/v1.0.0)

Input size

any H x W >= 32, padded to a multiple of 32 Tested up to (portable, fp16, RTX 5060 Ti 16 GB): matanyone 3000x4000 (14.5 GiB peak allocated, 15.1 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
matanyone 1220 1205 – – – 2978 / 3208 2719 / 2908 –

Startup and first call

model load (s): original portable kernels first call (s): original portable kernels
matanyone 3.39 0.40 – 2.37 1.87 –

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)
matanyone 1080x1920 1205 ms fails: load: BackendUnavailableError: matanyone@1 (portable) has no fails: BackendUnavailableError: matanyone@1 (portable) has no expor – – – 2719 / 2908 – – –

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

Video matting, YouTubeMatte (MatAnyone's benchmark): each clip at 512 x 288 with the authors' first-frame mask, the authors' evaluation settings (1 warm-up step, mask closing 4 px); 8-bit alpha against the ground truth: mean absolute and squared difference and the temporal coherence error dtSSD (lower is better), averaged over frames, then clips. Original = the original code named under Details, same checkpoint and protocol.

variant dataset original fp32 original fp16 portable note
matanyone YouTubeMatte 512 x 288, every 2nd clip (32 x 100 frames), first-frame mask, MAD x 1000 / MSE x 1000 / dtSSD x 100 2.62 / 0.99 / 1.65 2.64 / 1.00 / 1.65 2.64 / 1.00 / 1.65

Measured on NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks e97998ab, 2026-11-14.

Parity with the original code

Every variant is checked against reference outputs of the original code at its pinned commit. CPU, float32: max |diff| <= 1e-06 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 8.3e-05 and p99 <= 0.0001 (absolute error of the output alpha).

Usage

from fastforks import matting

# non-commercial weights: run with FASTFORKS_NONCOMMERCIAL=1 in the environment
model = matting.load("matanyone")  # 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: matanyone.

Kernels backend

No kernels backend: not implemented: ResNet encoders plus a memory readout and small object transformer per frame; portable runs 1.2 % faster than the original fp16 at 1080x1920 (1205 vs 1220 ms) with 9 % lower peak allocated memory (2719 vs 2978 MB) and identical task accuracy (YouTubeMatte MAD 2.636 both); against the original fp32 at 512x288 portable fp16 is 5 % slower per frame (20.5 vs 19.4 ms) with 24 % less memory, so the speed bar holds at 1080p and against fp16 only.

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

Collection including fastforks/matanyone