Instructions to use Chenyi007/Matting-Anything-2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sam2
How to use Chenyi007/Matting-Anything-2 with sam2:
# Use SAM2 with images import torch from sam2.sam2_image_predictor import SAM2ImagePredictor predictor = SAM2ImagePredictor.from_pretrained("Chenyi007/Matting-Anything-2") with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16): predictor.set_image(<your_image>) masks, _, _ = predictor.predict(<input_prompts>)# Use SAM2 with videos import torch from sam2.sam2_video_predictor import SAM2VideoPredictor predictor = SAM2VideoPredictor.from_pretrained("Chenyi007/Matting-Anything-2") with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16): state = predictor.init_state(<your_video>) # add new prompts and instantly get the output on the same frame frame_idx, object_ids, masks = predictor.add_new_points(state, <your_prompts>) # propagate the prompts to get masklets throughout the video for frame_idx, object_ids, masks in predictor.propagate_in_video(state): ... - Notebooks
- Google Colab
- Kaggle
Matting Anything 2
Towards Video Matting for Anything · ICLR 2026
Official experimental weights for promptable video matting with points, boxes or masks. The main model uses Hiera Large, the Promptable Dual-mode Decoder (PDD), Memory-Separable Siamese (MSS) and rank-16 LoRA adapters. MEMatte refines RGB and the predicted trimap into an alpha matte.
Checkpoints
| File | Description | Size |
|---|---|---|
mam2_main.pt |
Original experimental checkpoint_100.pt |
1,035,483,060 bytes |
mam2_matter.pth |
Associated MEMatte refinement weights | 116,874,309 bytes |
Both files preserve the original checkpoint bytes. Their SHA-256 hashes and
sizes are recorded in weights.json and SHA256SUMS.
The inference configuration pins weight revision 0e0a8d0d9034b00c4baca88f1a0bb1397e724905.
Use with the MAM2 source release
Install the Matting Anything 2 source project in a dedicated Python environment:
python -m pip install -e '.[demo]'
The source release provides the modified SAM2 package, PDD, MSS, MEMatte and the configuration loader. Download and verify the weights with:
mam2-download --config configs/inference.yaml
Launch the interactive demo:
CUDA_VISIBLE_DEVICES=0 OMP_NUM_THREADS=4 \
mam2-demo --config configs/web.yaml
Open http://127.0.0.1:7860, choose a video, add points or a box, and start
matting. The inference CLI uses the same checkpoint configuration:
CUDA_VISIBLE_DEVICES=0 mam2-infer --config configs/inference.yaml \
input.source=inputs/example.mp4 \
inference.matter_max_size=2048
Both entry points download the weights on first use and reuse the cache.
Public downloads require no login. For offline use after downloading, set
huggingface.local_files_only=true with the same cache and revision.
Configuration files are included under configs/.
Attribution
The main model is based on SAM2. The refinement checkpoint is the MEMatte weight used with the original MAM2 experiments. Source attribution and code licenses are provided with the MAM2 source release.
Citation
@inproceedings{zhang2026mattinganything2,
title={Matting Anything 2: Towards Video Matting for Anything},
author={Zhang, Chenyi and Lin, Yiheng and Wei, Yunchao and Wang, Hongsong and Shan, Caifeng and Zhao, Fang},
booktitle={International Conference on Learning Representations},
year={2026}
}