Nodes/ComfyUI-segment-anything-2/Sam2AutoSegmentation
ComfyUI Node Runs on cloud

Sam2AutoSegmentation

Segment everything, no prompts needed

By kijai·Created 2 years ago·Updated 10 months ago· 1,210
Sam2AutoSegmentation
  • sam2_model
  • image
  • mask
  • segmented_image
  • bbox
points_per_side32
points_per_batch64
pred_iou_thresh0.80
stability_score_thresh0.95
stability_score_offset1.00
mask_threshold0.00
crop_n_layers0
box_nms_thresh0.70
crop_nms_thresh0.70
crop_overlap_ratio0.34
crop_n_points_downscale_factor1
min_mask_region_area0.00
use_m2mfalse
keep_model_loadedtrue

The other two segmentors want you to point at something. This one doesn't. Sam2AutoSegmentation grids points across the entire image and returns a mask for every object it finds - no clicks, no boxes, no text prompt. It's the "just segment everything" button. Hand it a photo and it comes back with masks for the person, the chair, the lamp, the rug, the window, all at once.

When's that actually useful? When you don't know in advance what's in the frame, or you want per-object masks for a downstream picker, or you're building a dataset and need every region carved out automatically. It's a different job from the point-driven node. Sam2Segmentation is a scalpel - you know what you want, you go get it. Auto is a net - cast it and see what comes back. If you already know you want "the dog," don't use this; prompt it directly. Auto shines when the goal is coverage, not a specific target.

How it works

This is SAM2's automatic mask generator. Instead of you supplying prompt points, it lays down a regular grid of points (that's points_per_side - 32 by default means a 32×32 grid), runs the model at each, and collects every distinct mask that comes back. Then it filters: masks below a quality bar get dropped, near-duplicates get merged, and what survives is your set of object masks. Most of this node's many parameters are the knobs on that filter-and-dedup stage.

Fair warning: it's the heaviest node in the pack per image, because it's effectively running the model across hundreds of seed points. More points = finer coverage but slower.

The inputs that matter

Two you must set, and then a wall of filtering floats. Don't be intimidated - the defaults are sane, and you only touch a couple:

  • sam2_model (SAM2MODEL) - loader must be in automaskgenerator mode. Wrong mode, wrong node, error.
  • image (IMAGE) - what to segment.
  • points_per_side (INT, default 32) - the density dial, and the one you'll actually adjust. Higher finds smaller objects but costs time and can over-segment; lower is faster and coarser.
  • pred_iou_thresh (default 0.8) and stability_score_thresh (default 0.95) - the quality gates. Getting junk masks? Raise them. Missing objects you wanted? Lower them a touch.
  • min_mask_region_area - bumps out tiny speckle masks. Useful when auto-seg gives you a hundred fragments.

The rest - points_per_batch, stability_score_offset, mask_threshold, crop_n_layers, box_nms_thresh, crop_nms_thresh, crop_overlap_ratio, crop_n_points_downscale_factor, use_m2m - are fine-tuning for the crop-and-dedup pipeline. Leave them at defaults until you have a specific reason. keep_model_loaded (default true) keeps the model resident between runs.

Three outputs, which is what makes this node handy:

  • mask (MASK) - the set of object masks.
  • segmented_image (IMAGE) - a colorized preview of the segmentation, so you can eyeball what it found without wiring a mask-to-image node.
  • bbox (BBOX) - bounding boxes for the detected regions, handy for downstream cropping or picking.

How to install it

Ships in the pack. ComfyUI Manager → search ComfyUI-segment-anything-2 → install → restart. Or:

cd ComfyUI/custom_nodes
git clone https://github.com/kijai/ComfyUI-segment-anything-2

Restart after. The loader pulls the weights; ComfyICU bundles the pack in its shared image.

Common issues

  • Loader not in automaskgenerator mode. Same family gotcha as the rest of the pack - this node needs a model loaded specifically for auto mode.
  • Way too many masks / over-segmented. Lower points_per_side, raise pred_iou_thresh and stability_score_thresh, and set min_mask_region_area to drop the specks.
  • Missing small objects. The opposite: raise points_per_side and ease the two thresholds down a little. It's a tradeoff - finer grids cost real time.
  • Slow or OOM. This is the most expensive node here. Drop points_per_side, use a smaller Hiera variant, or shrink the input image. If you actually know what you're after, the point-prompted Sam2Segmentation is dramatically cheaper - reach for auto only when broad coverage is the goal.
CategorySAM2

Inputs (16)

NameTypeDefaultDescription
sam2_modelSAM2MODEL
imageIMAGE
points_per_sideINT32
points_per_batchINT64
pred_iou_threshFLOAT0.800–1
stability_score_threshFLOAT0.950–1
stability_score_offsetFLOAT1.000–1
mask_thresholdFLOAT0.000–1
crop_n_layersINT0
box_nms_threshFLOAT0.700–1
crop_nms_threshFLOAT0.700–1
crop_overlap_ratioFLOAT0.340–1
crop_n_points_downscale_factorINT1
min_mask_region_areaFLOAT0.000–1
use_m2mBOOLEANfalse
keep_model_loadedBOOLEANtrue

Outputs (3)

NameTypeDescription
maskMASK
segmented_imageIMAGE
bboxBBOX