MatteAnything_LoadVITMatteModel
The model that turns a rough mask into real alpha
- VIT_MATTE_MODEL
Here's the thing nobody says about Matte Anything: SAM gives you a hard mask, and a hard mask is wrong. Every pixel is either in or out, which is a death sentence for flyaway hair, glasses, and anything even slightly translucent. This node loads the model that fixes exactly that - ViTMatte, the matting network at the heart of the whole pack.
Matte Anything is the ComfyUI port of the 2023 academic project of the same name from HUST's vision lab (arXiv 2306.04121, "Interactive Natural Image Matting with Segment Anything Models"). Its whole pitch is that SAM finds the object, but a separate matting model - ViTMatte - refines the boundary into fractional alpha you can actually composite. MatteAnything_LoadVITMatteModel is where that second model enters your graph.
How it works
The node reads a checkpoint from your ComfyUI/models/matte/ folder and rebuilds the ViTMatte architecture from the pack's bundled config (Matte_Anything/configs/matte_anything.py - a ViT-B backbone, embed_dim 768, 12 heads, plus the detail-capture decoder). Loading is done through detectron2's DetectionCheckpointer, which is a hint about what you're about to install (more on that below). The result comes out as a VIT_MATTE_MODEL object ready for MatteAnything_GenerateVITMatte.
Inputs and outputs that matter
Only two inputs, and you'll mostly leave them alone:
- model_name - a dropdown of whatever checkpoints you've dropped in
models/matte/. The expected file is the original repo'sViTMatte_B_DIS.pth, but any ViTMatte-B checkpoint should load. - device_mode -
AUTO,Prefer GPU, orCPU. Note this loader treatsAUTOandPrefer GPUidentically: both put the model on your GPU, and onlyCPUforces CPU. That's different from the SAM loader in this same pack, which is a classic "same dropdown, different meaning" trap.
Output is a single VIT_MATTE_MODEL that wires straight into MatteAnything_GenerateVITMatte. There's nothing else to do with it.
Installing this pack
ComfyUI Manager is the easy route - search for Comfy_KepMatteAnything and hit install. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/M1kep/Comfy_KepMatteAnything
Then restart ComfyUI. The requirements.txt pulls three heavy academic dependencies: segment-anything, detectron2, and groundingdino-py. Detectron2 is the one that will eat an afternoon - it's a native C++/CUDA build, painful on Windows and usually smooth on Linux. This node in particular can't work without it, because the checkpoint loader lives inside detectron2.
Then the models. Create the folders and drop the files in:
mkdir -p ComfyUI/models/{sams,dino,matte}
For this node you need the ViTMatte checkpoint in models/matte/. The official link lives in the bundled Matte-Anything README and it's a Google Drive link - the kind that rots. It's the least discoverable model in the pack; if the link has died, look for a ViTMatte vit_b release rather than the SAM/DINO weights, because dropping a wrong-family checkpoint in here gets you a key-mismatch error from detectron2.
Gotchas
- The config path is relative. The pack looks for its config at
./custom_nodes/Comfy_KepMatteAnything/Matte_Anything/configs/matte_anything.py, relative to wherever you launched ComfyUI from. Launch from the ComfyUI directory (the normal setup) and it's fine; launch from anywhere else and this node dies with a "config not found" style error before you even pick a model. - Don't expect speed miracles. ViTMatte-B is a 2023-era ViT; it's fine for a single image but it's not the instant-40ms tooling the modern cutout packs advertise.
Honest take: if you just need a cutout, this whole pack is overkill and you'd be happier with a one-model modern alternative. But if you want genuine soft alpha and a trimap you can actually tune, this is the classic way to get it - and this node is the reason the matte part of "Matte Anything" isn't marketing.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| model_name | COMBO | 0 options: | |
| device_mode | COMBO | 3 options: AUTO, Prefer GPU, CPU |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| VIT_MATTE_MODEL | VIT_MATTE_MODEL | — |