SAMLoader (Impact)
Load Segment Anything so your masks follow the object, not a box
- SAM_MODEL
SAMLoader is the little node that loads Meta's Segment Anything Model so the rest of the Impact Pack can use it. On its own it does nothing visible - it's a loader. The point is what it feeds: a SAM_MODEL that turns a rough rectangle into a mask that actually hugs the object.
Here's why you'd bother. A bounding-box detector says "there's a face, roughly in this box." A box is a blunt instrument - it grabs the face and a slice of hair, neck, and background. SAM takes that box and traces the real silhouette inside it. When you're inpainting or running a detail pass, a mask that follows the actual outline means far fewer visible seams, because you're only regenerating the thing you meant to. That's the whole job. In the Impact Pack world SAM is the refinement layer that sits between "found it" and "fixed it."
This node comes from the ComfyUI Impact Pack, ltdrdata's detect-crop-refine suite - the same author who wrote ComfyUI Manager, which makes him one of the two or three people the practical ComfyUI experience actually rests on. Impact Pack is the ComfyUI answer to A1111's ADetailer, and SAM is one of the detectors it wires into that pipeline.
How it works
SAM is a general-purpose segmenter: give it an image plus a hint (a point, a box, a rough mask) and it returns a clean segment. SAMLoader just reads a .pth checkpoint off disk and hands the loaded model downstream. The model files live in ComfyUI/models/sams, and the base pack auto-downloads a starter model (sam_vit_b_01ec64.pth, the small ViT-B variant) on first install. Bigger, sharper variants (ViT-L, ViT-H) and, since Impact Pack v8.18, the newer SAM2 models drop into the same folder and show up in the dropdown.
You almost never wire SAM in by itself. It plugs into SAMDetector (combined), Simple Detector (SEGS), or the sam_model_opt slot on FaceDetailer, where it sharpens whatever a bbox detector found.
The inputs and outputs that matter
There are only two inputs, and one output:
model_name- which SAM checkpoint to load, from whatever's inmodels/sams. If the dropdown is empty, nothing got downloaded (more on that below).device_mode-AUTO,Prefer GPU, orCPU.AUTOis the sane default: it lets Impact manage where the model sits and hand VRAM back when it's idle.Prefer GPUkeeps it resident on the GPU (faster on repeated runs, more VRAM parked).CPUforces it off the GPU entirely - dog-slow, but a genuine escape hatch when you're out of VRAM.
The single output is SAM_MODEL, which is not an image or a mask - it's the loaded model object. Wire it straight into the sam_model_opt (or equivalent) input of a detector or detailer node.
How to install it
The node ships in the Impact Pack, so you install the pack, not the node. Easiest path is ComfyUI Manager: search ComfyUI Impact Pack, click Install, restart. Manual works too:
cd ComfyUI/custom_nodes
git clone https://github.com/ltdrdata/ComfyUI-Impact-Pack comfyui-impact-pack
cd comfyui-impact-pack
python -m pip install -r requirements.txt # use ComfyUI's python; python_embeded on portable
then restart ComfyUI. Note that since v7.6 there's no silent auto-install - installing through Manager or running that pip install is the supported route. On Linux you may also need the system libs libgl1-mesa-glx and libglib2.0-0 for OpenCV. First launch pulls the starter SAM model into models/sams automatically.
Common issues & troubleshooting
The model_name dropdown is empty. Nothing landed in ComfyUI/models/sams. Either the auto-download was skipped (a skip_download_model file in custom_nodes/ disables it, and a bare manual clone can miss the download step), or you never restarted after install. Fix: drop any SAM checkpoint into that folder manually - ComfyUI Manager can fetch several - and restart.
You picked a SAM2 model and it errored. SAM2 is only supported from v8.18 on, and some nodes (the SAM2 video detector) require a SAM2 model selected here rather than the classic one. Match the model to what the downstream node expects.
Do you even need it? Honestly, often not. In practice bbox-only detection is "usually fine," and people reach for SAM when a rectangular mask is leaving obvious seams around a face or object. If your results already look clean, SAM is one more model in VRAM for no gain. Add it when the seams show up, not before.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| model_name | COMBO | The detection accuracy varies depending on the SAM model. ESAM can only be used if ComfyUI-YoloWorld-EfficientSAM is installed. | |
| device_mode | COMBO | AUTO: Only applicable when a GPU is available. It temporarily loads the SAM_MODEL into VRAM only when the detection function is used. Prefer GPU: Tries to keep the SAM_MODEL on the GPU whenever possible. This can be used when there is sufficient VRAM available. CPU: Always loads only on the CPU. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| SAM_MODEL | SAM_MODEL | — |