Practical human video matting framework that preserves fine details by avoiding segmentation-like boundaries, while also showing enhanced robustness under challenging real-world conditions.
MatAnyone 2 takes a video and a first-frame segmentation mask as input, and produces:
- Foreground output — the separated person/object with transparent background
- Alpha matte output — the alpha channel showing the matting quality
The Gradio demo includes built-in SAM (Segment Anything Model) support, so you can interactively click to create masks directly in the web UI — no need to prepare masks externally.
- Install — Click the Install button in Pinokio. This will clone the repo, set up a Python virtual environment, and install all dependencies.
- Start — Click Start to launch the Gradio web UI.
- Upload — Drop a video or image into the web interface.
- Mask — Click on the subject to create a segmentation mask. Use Positive/Negative point prompts to refine.
- Run — Click "Video Matting" or "Image Matting" to process.
- Results — Download the foreground and alpha matte outputs.
from matanyone2.utils.get_default_model import get_matanyone2_model
from matanyone2.inference.inference_core import InferenceCore
# Load model
model = get_matanyone2_model("pretrained_models/matanyone2.pth", "cuda")
model = model.to("cuda").eval()
# Run inference
processor = InferenceCore(model, cfg=model.cfg)cd app
python inference_matanyone2.py -i inputs/video/test-sample1 -m inputs/mask/test-sample1.png# When the Gradio server is running locally:
curl -X POST http://localhost:8000/api/predict \
-H "Content-Type: application/json" \
-d '{"data": ["video_path", "mask_data"]}'- MatAnyone 2 by Peiqing Yang et al.
- Built upon Cutie and Segment Anything