SAM Predictor
SAM segmentation the Impact Pack way, without Impact Pack
- sam_model
- image
- bbox
- MASK
- SEGS
The precise-mask node
Detectors give you boxes; SAM gives you masks that actually follow the outline - hair, fingers, the whole silhouette. SAMPredictorNode runs Meta's Segment Anything Model on your image and returns a precise mask (plus a SEGS output). The author's README is disarmingly honest about the pedigree: it's "basically copied from Impact-Pack." That's good news, because it means the node speaks Impact Pack's language - the SEGS output plugs straight into DetailerForEach and friends, which is exactly how the pack's own detailer example workflow wires it.
How it works
You need three things connected: a SAM_MODEL, the image, and optionally a bbox to tell SAM where to look. Under the hood it's the official segment_anything library's SamPredictor, so quality tracks the model you load. The inputs worth knowing:
sam_model- comes from SAM Loader for SAMPredictorNode (same pack, search "SAM Loader"), which loads a checkpoint fromComfyUI/models/sams.threshold(default 0.4) - confidence floor for keeping masks.bbox- optional. If you feed it a detection box, SAM segments within it. The tooltip explicitly suggests wiring Mask to BBox here.points_method- the fun one. "None" means no point prompts; the others (center-1,vertical-2,rectangle-4,diamond-4, …) auto-generate point prompts inside the box to steer SAM. Worth experimenting with if single-box prompting gives mushy results.merge_options- "Merge All" unions every mask, "BBox Merge" merges per box, "No Merge" keeps each separate.crop_factor(default 3) - how far around the box theSEGScrop extends.
Outputs: MASK (ready for inpainting, masking, compositing) and SEGS (the Impact Pack format - this is what makes the node detailer-compatible).
Install
ComfyUI Manager → search "comfyui_imgutils", or:
cd ComfyUI/custom_nodes
git clone https://github.com/LK-168/comfyui_imgutils
Restart ComfyUI. SAM models do NOT auto-download - unlike the imgutils detection models, you grab a checkpoint yourself and drop it in ComfyUI/models/sams, the same folder Impact Pack uses. vit_h / vit_l / vit_b are auto-detected from the filename. Two quirks from the README: that folder is not affected by extra_model_paths.yaml (the author couldn't crack that and invites a PR), and the SAM Loader's AUTO device mode shuttles the model into VRAM only while predicting, which is the polite way to run it on a small card.
Common issues
- SAM Loader's dropdown is empty. No checkpoint in
models/sams. That's a model-file problem, not a code problem. - "Input 'sam_model' does not contain a valid SAMWrapper." You connected a model that isn't from this pack's SAM Loader. It's checking for a specific wrapper; use the bundled loader.
- Mask looks like the whole image. No
bbox, no points, low threshold - SAM with nothing to go on returns something unhelpful. Give it a box.
Precise masks without hand-drawing, plus SEGS for the detailing crowd - that's the node's whole pitch, and it delivers.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| sam_model | SAM_MODEL | — | |
| image | IMAGE | — | |
| threshold | FLOAT | 0.400–1 | Confidence threshold to include masks |
| bbox | BBOX | Optional bounding box [x_min, y_min, x_max, y_max] (pixel space). Connect a MaskToBBoxNode output or similar. | |
| points_method | COMBO | None | Method to generate points for the SAM model. 'None' means no points |
| merge_options | COMBO | Merge All | How to merge masks if multiple are generated. 'Merge All' combines all masks, 'BBox Merge' merges masks within the same bbox, 'No Merge' returns all masks separately. |
| crop_factoropt | FLOAT | 3.01–100 | Factor to crop the image for SEG |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| MASK | MASK | — |
| SEGS | SEGS | — |