Nodes/comfyui_imgutils/SAM Predictor
ComfyUI Node

SAM Predictor

SAM segmentation the Impact Pack way, without Impact Pack

By LK-168·Created about a year ago·Updated about a year ago· 1
SAM Predictor
  • sam_model
  • image
  • bbox
  • MASK
  • SEGS
threshold0.40
points_methodNone
merge_optionsMerge All
crop_factor3.0

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 from ComfyUI/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 the SEGS crop 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.

Categoryimgutils/sam

Inputs (7)

NameTypeDefaultDescription
sam_modelSAM_MODEL
imageIMAGE
thresholdFLOAT0.400–1Confidence threshold to include masks
bboxBBOXOptional bounding box [x_min, y_min, x_max, y_max] (pixel space). Connect a MaskToBBoxNode output or similar.
points_methodCOMBONoneMethod to generate points for the SAM model. 'None' means no points
merge_optionsCOMBOMerge AllHow 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_factoroptFLOAT3.01–100Factor to crop the image for SEG

Outputs (2)

NameTypeDescription
MASKMASK
SEGSSEGS