MatteAnything_InitSamPredictor
The quiet middleman that bakes your image into SAM
- image
- sam_model
- SAM_PREDICTOR
Some nodes do the flashy work; MatteAnything_InitSamPredictor does the expensive homework. It takes your image and the SAM model from MatteAnything_SAMLoader, and it produces the SAM_PREDICTOR object that the rest of the pipeline needs. No visible output, no knobs to turn - but if this node feels slow, that's not a bug, it's the bill coming due.
Why it exists
SAM works in two stages. First it encodes your image into a feature embedding - a one-time, per-image cost that runs a full ViT over the whole frame. Then, with that embedding cached, it can answer "give me the mask for this box/point" almost instantly, as many times as you like. InitSamPredictor is where the first stage happens: it builds a SamPredictor and calls set_image() on it, which is exactly the encoding step.
That's why the node needs both the image and the model at once, and why it has no other inputs. You're paying for the encoding here so that MatteAnything_SAMMaskFromBoxes can be fast later.
Inputs and outputs
- image - the same image that goes through the whole pipeline. Keep it consistent with what
DinoBoxessaw, or your boxes and masks will be computed against different frames. - sam_model - from
MatteAnything_SAMLoader. - Output: one
SAM_PREDICTOR, which feedsMatteAnything_SAMMaskFromBoxes.
There's nothing else on this node. No settings, no modes. It's the definition of a plumbing node.
The slowdown nobody warns you about
Here's where the device_mode quirk from the SAM loader comes back to bite. If you left MatteAnything_SAMLoader on its default AUTO setting, your SAM model is sitting on the CPU - and the image encoding this node runs happens on whatever device the model is on. That turns the pack's "one-time embedding" step into a very slow CPU slog, and since this node caches nothing between runs, you pay it every single time.
If InitSamPredictor is where your workflow stalls, the fix is almost always upstream: set MatteAnything_SAMLoader to Prefer GPU. The node isn't slow; the model it was handed is in the wrong place.
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. This node needs segment-anything and detectron2 from the pack's requirements.txt (detectron2 being the painful one, especially on Windows), plus the SAM weights:
mkdir -p ComfyUI/models/sams
# sam_vit_h_4b8939.pth into ComfyUI/models/sams/
Gotchas
- A new
SAM_PREDICTORper image. If you're batch-processing, remember this node holds one image's embedding. Swap images and you need a fresh predictor, so structure your batch so each image gets its ownInitSamPredictorinstance. - The annotated-image trap doesn't apply here, but the resolution one does. The predictor encodes at the resolution you feed it; the mask comes back at that same resolution, so don't upscale before this node and expect extra detail - you'll just pay more for the encoding.
Honest take: this is the least glamorous node in the pack and the one beginners most often suspect of being broken. It isn't. Give it a GPU-backed SAM and it's a quiet handoff; give it the default AUTO loader and it's a hostage situation. That upstream toggle is the entire difference.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| sam_model | SAM_MODEL | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| SAM_PREDICTOR | SAM_PREDICTOR | — |