Models · Matting

MatAnyone

MatAnyone (Yang et al., S-Lab NTU, CVPR 2025): video matting of one object: from a mask of the object in the first frame it tracks the object and outputs a soft alpha matte (hair, motion blur) for every frame, with a memory of earlier frames. Non-commercial code and weights (S-Lab License 1.0).

experimental Fork of pq-yang/MatAnyone@e5ddc53 · backends: portable, kernels

Checkpoint matanyone

Paper 2025 Added in 0.2.0 Evaluated with 0.2.0

Portable, RTX 5060 Ti 16 GB 1205 ms 1080x1920, fp16
vs the faster original 1.0× original fp16: 1220 ms
Peak memory 2,719 MiB original: 2,978 MiB
Accuracy vs original fp32 +0.01 portable mad, YouTubeMatte 512 x 288 (2.62 original)

Use it

pip install fastforks

Lean install with only what this model needs: pip install "fastforks-core[nc]"

from fastforks import matting

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

The weights are non-commercial: fastforks downloads them only with FASTFORKS_NONCOMMERCIAL=1 set.

fastforks bench matanyone

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); pq-yang/MatAnyone@e5ddc534c1ff process_video loop on frames in memory, cv2 mask closingfp16 1220–2,978 MiB/3,208 MiB1.51.53
Portable fp32fp32not measured ––––
Portablefp16 12051.0×2,719 MiB/2,908 MiB0.41.87
Kernelsnot measured ––––
Portable + torch.compileload: BackendUnavailableError: matanyone@1 (portable) has nofails––––
TensorRTBackendUnavailableError: matanyone@1 (portable) has no exporfails––––

Measured on RTX 5060 Ti 16 GB, torch 2.14.1+cu130, 2026-11-14. 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-14Originalfp326473 6,365 MiB process–1080x1920
Portablefp165907 3,851 MiB processmatches1080x1920
Portablefp326198 6,015 MiB processmatches1080x1920
Kernelsfp32not 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

Non-commercial only

Code
LicenseRef-noncommercial LICENSE
Weights
LicenseRef-noncommercial source
Training data
  • code: LicenseRef-noncommercial (noncommercial)
  • weights: LicenseRef-noncommercial

Our reading of the licences, not legal advice.

Weights

matanyone.pth 141 MB· hosted on GitHub

fastforks downloads and checks these files on first use (fastforks download matanyone). Non-commercial weights need FASTFORKS_NONCOMMERCIAL=1.

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.

YouTubeMatte 512 x 288

every 2nd clip (32 x 100 frames), first-frame mask, MAD x 1000 / MSE x 1000 / dtSSD x 100

Rundtypemad ↑mse ↑dtssd ↑Δ mad vs fp32 originalclipsms / clip
Original fp32fp322.620.991.65 reference 32 –
Original fp16fp162.641.001.65 +0.01 32 –
Portable fp32fp322.620.991.65 ±0.00 32 –
Portablefp162.641.001.65 +0.01 32 –
Kernelsnot measured

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 authors’ code, same checkpoint and protocol. Measured on original fp32, original fp16: RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-14; portable fp32, portable: RTX 5060 Ti, torch 2.14.1+cu130, fastforks e97998ab, 2026-11-14.

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

CheckToleranceMeasured
CPU fp32, max |diff|≤ 0.000001 not recorded
GPU default dtypes, mean |diff|≤ 0.000083 0.00005
GPU default dtypes, p99 |diff|≤ 0.0001 0

Recorded for matanyone on RTX 5060 Ti, torch 2.10.0+cu130, 2026-11-17, with these kernels: image_normalize

Details

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.

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 (14.5 GiB allocated)
Options
  • warmup=10>= 0· changes the output
  • dilate=10>= 0· changes the output
  • erode=10>= 0· changes the output
Outputs
alpha
CUDA kernels
  • image_normalize
Apple (MPS)
fp32, fp16
Full reference, generated from the repository

MatAnyone (Yang et al., S-Lab NTU, CVPR 2025): video matting of one object: from a mask of the object in the first frame it tracks the object and outputs a soft alpha matte (hair, motion blur) for every frame, with a memory of earlier frames. Non-commercial code and weights (S-Lab License 1.0).

Commercial use: no (code: LicenseRef-noncommercial (noncommercial); weights: LicenseRef-noncommercial).

variantinputbackendtime (ms)peak memory (MiB, allocated / reserved)
matanyonesynthetic (1080x1920)original
portable
kernels
portable + torch.compile
TensorRT fp16
1220
1205
–
fails: load: BackendUnavailableError: matanyone@1 (portable) has no
fails: BackendUnavailableError: matanyone@1 (portable) has no expor
2978 / 3208
2719 / 2908
–
–
–
Details
  • Original code: https://github.com/pq-yang/MatAnyone at e5ddc534c1ff
  • Code licence: LicenseRef-noncommercial (noncommercial); files: LICENSE
  • Weights licence: LicenseRef-noncommercial
  • 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)
  • 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.)
  • Options: warmup = 10 (>= 0; also n_warmup), dilate = 10 (>= 0; also r_dilate), erode = 10 (>= 0; also r_erode)
  • Kernel libraries: image_normalize
  • Variants: matanyone
  • 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): matanyone 3000x4000 (14.5 GiB peak allocated, 15.1 reserved)
  • matanyone original 1080x1920: the authors' mixed-precision option (float16); pq-yang/MatAnyone@e5ddc534c1ff process_video loop on frames in memory, cv2 mask closing
  • matanyone load / first call: original 3.39 s / 2.37 s, portable 0.4 s / 1.867 s
  • Protocol, first call, 3 warm-up, peak reset, median of 3 rounds x median of 5

Measured

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.

variantdatasetoriginal fp32original fp16portableportable fp32note
matanyoneYouTubeMatte 512 x 288, every 2nd clip (32 x 100 frames), first-frame mask, MAD x 1000 / MSE x 1000 / dtSSD x 1002.62 / 0.99 / 1.652.64 / 1.00 / 1.652.64 / 1.00 / 1.652.62 / 0.99 / 1.65

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

Parity

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

variantkernels error vs original, mean / p99GPU, torchkernels used
matanyone5e-05 / 0.0RTX 5060 Ti, torch 2.10.0+cu130image_normalize@592f5511307a:sm_120

Example output

No example rendered for this checkpoint yet.