MatteAnything_SAMLoader
Where the Matte Anything pipeline starts
- SAM_MODEL
Every Matte Anything workflow starts here. MatteAnything_SAMLoader loads Meta's Segment Anything Model into your graph, and everything downstream - the boxes, the mask, and eventually the matte - is built on top of the object SAM finds. Think of it as the pack's entrance ticket: nothing else in Comfy_KepMatteAnything runs without one of these SAM_MODEL objects floating around.
It's also the node where the pack's one real design quirk lives, so read the device_mode section before you queue your first workflow and then wonder why it's crawling.
How it works
The loader scans your ComfyUI/models/sams/ folder and figures out which SAM variant you have from the filename: vit_h → ViT-H, vit_l → ViT-L, anything else → ViT-B. It hands the checkpoint to sam_model_registry from the official segment-anything library, then wraps it up as a SAM_MODEL. That's it - loading SAM doesn't do any inference yet; the actual image encoding happens later in MatteAnything_InitSamPredictor.
The device_mode trap
The input has three choices - AUTO, Prefer GPU, CPU - and AUTO is the default. Here's the thing: in the actual code, AUTO leaves the model exactly where it is, which is the CPU. Only Prefer GPU explicitly moves it to your GPU. So the "smart" default is secretly the slow one, and you'll be running SAM's image encoder on CPU until you switch it.
This is a known wrinkle, not a mystery - the pack's device handling was recently reworked via a community PR that unhardcoded the device, and the semantics didn't end up intuitive. If you're on a GPU box, set Prefer GPU. If you genuinely want CPU, pick CPU. AUTO is a coin flip you didn't ask for.
Inputs and outputs
- model_name - dropdown of checkpoints in
models/sams/. For the full Matte Anything experience you want the big one,sam_vit_h_4b8939.pth(~2.5GB); ViT-B runs lighter but the mask quality drops with it. - device_mode - see above.
- Output: one
SAM_MODEL, which feedsMatteAnything_InitSamPredictor.
Installing this pack
ComfyUI Manager, search Comfy_KepMatteAnything, install. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/M1kep/Comfy_KepMatteAnything
then restart ComfyUI. The dependencies are the heavy part: segment-anything, detectron2, and groundingdino-py all get pulled from git. Detectron2 is the notorious one - a native C++/CUDA build that's genuinely annoying on Windows and mostly painless on Linux.
For this node specifically, you need the SAM weights:
mkdir -p ComfyUI/models/sams
# sam_vit_h_4b8939.pth from the official Meta release
Gotchas
AUTOmeans CPU here. Already covered, but it's worth repeating because it's the most common "why is this slow" answer in the pack.- The README won't save you. The pack's own README is essentially empty; the real documentation lives in the bundled
Matte_Anything/subfolder (the original academic repo), which assumes you're running their Gradio app, not ComfyUI. The folder layout is the part you have to figure out yourself. - Model file must match a supported name pattern. Drop a checkpoint with an unusual name and the loader will guess
vit_band then fail to build the model from mismatched weights. Name it with the variant in it.
Honest take: SAM is the dependable, boring part of this pack - it's 2023 technology and it shows in speed, but it's the same SAM that was the community's masking standard for years. Load it, set Prefer GPU, and move on to the nodes that do the interesting work.
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 |
|---|---|---|
| SAM_MODEL | SAM_MODEL | — |