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
- Paper MatAnyone: Stable Video Matting with Consistent Memory Propagation CVPR 2025 · first released 24 Jan 2025
Checkpoint matanyone
Paper 2025 Added in 0.2.0 Evaluated with 0.2.0
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)
| Backend | dtype | Time per call (ms) | vs original fp16 | Peak memory allocated / reserved | Load (s) | First call (s) |
|---|---|---|---|---|---|---|
| Original fp32 | fp32 | not measured | – | – | – | – |
| Original fp16the authors' mixed-precision option (float16); pq-yang/MatAnyone@e5ddc534c1ff process_video loop on frames in memory, cv2 mask closing | fp16 | 1220 | – | 2,978 MiB/3,208 MiB | 1.5 | 1.53 |
| Portable fp32 | fp32 | not measured | – | – | – | – |
| Portable | fp16 | 1205 | 1.0× | 2,719 MiB/2,908 MiB | 0.4 | 1.87 |
| Kernels | not measured | – | – | – | – | |
| Portable + torch.compileload: BackendUnavailableError: matanyone@1 (portable) has no | fails | – | – | – | – | |
| TensorRTBackendUnavailableError: matanyone@1 (portable) has no expor | fails | – | – | – | – |
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
| Device | Backend | dtype | ms / call | Peak memory | Output vs reference | Input |
|---|---|---|---|---|---|---|
| Apple M1 Pro 16 GB MPS, torch 2.14.1, 2026-11-14 | Original | fp32 | 6473 | 6,365 MiB process | – | 1080x1920 |
| Portable | fp16 | 5907 | 3,851 MiB process | matches | 1080x1920 | |
| Portable | fp32 | 6198 | 6,015 MiB process | matches | 1080x1920 | |
| Kernels | fp32 | not 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
-
- VM800 (MatAnyone video matting foregrounds) not stated, non-commercial
- Composition-1k (Adobe Deep Image Matting) research-only, non-commercial
- Distinctions-646 (image matting) not stated
- BG-20k (background images) MIT
- DVM background set (video backgrounds) not stated
- COCO 2017 (train, instance annotations) CC-BY-4.0
- YouTube-VIS 2021 (video instance segmentation) not stated
- Supervisely Person Dataset (human segmentation) noncommercial, non-commercial
- code: LicenseRef-noncommercial (noncommercial)
- weights: LicenseRef-noncommercial
Our reading of the licences, not legal advice.
Weights
matanyone.pth 141 MB· hosted on GitHubfastforks 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
| Run | dtype | mad ↑ | mse ↑ | dtssd ↑ | Δ mad vs fp32 original | clips | ms / clip |
|---|---|---|---|---|---|---|---|
| Original fp32 | fp32 | 2.62 | 0.99 | 1.65 | reference | 32 | – |
| Original fp16 | fp16 | 2.64 | 1.00 | 1.65 | +0.01 | 32 | – |
| Portable fp32 | fp32 | 2.62 | 0.99 | 1.65 | ±0.00 | 32 | – |
| Portable | fp16 | 2.64 | 1.00 | 1.65 | +0.01 | 32 | – |
| Kernels | not 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).
| Check | Tolerance | Measured |
|---|---|---|
| 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 outputdilate=10>= 0· changes the outputerode=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).
| variant | input | backend | time (ms) | peak memory (MiB, allocated / reserved) |
|---|---|---|---|---|
matanyone | synthetic (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; alson_warmup),dilate= 10 (>= 0; alsor_dilate),erode= 10 (>= 0; alsor_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):
matanyone3000x4000 (14.5 GiB peak allocated, 15.1 reserved) matanyoneoriginal 1080x1920: the authors' mixed-precision option (float16); pq-yang/MatAnyone@e5ddc534c1ff process_video loop on frames in memory, cv2 mask closingmatanyoneload / 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.
| variant | dataset | original fp32 | original fp16 | portable | portable fp32 | 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 | 2.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).
| variant | kernels error vs original, mean / p99 | GPU, torch | kernels used |
|---|---|---|---|
matanyone | 5e-05 / 0.0 | RTX 5060 Ti, torch 2.10.0+cu130 | image_normalize@592f5511307a:sm_120 |
Example output
No example rendered for this checkpoint yet.