Sam2AutoSegmentation
Segment everything, no prompts needed
- sam2_model
- image
- mask
- segmented_image
- bbox
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 inautomaskgeneratormode. 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) andstability_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
automaskgeneratormode. 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, raisepred_iou_threshandstability_score_thresh, and setmin_mask_region_areato drop the specks. - Missing small objects. The opposite: raise
points_per_sideand 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.
Inputs (16)
| Name | Type | Default | Description |
|---|---|---|---|
| sam2_model | SAM2MODEL | — | |
| image | IMAGE | — | |
| points_per_side | INT | 32 | — |
| points_per_batch | INT | 64 | — |
| pred_iou_thresh | FLOAT | 0.800–1 | — |
| stability_score_thresh | FLOAT | 0.950–1 | — |
| stability_score_offset | FLOAT | 1.000–1 | — |
| mask_threshold | FLOAT | 0.000–1 | — |
| crop_n_layers | INT | 0 | — |
| box_nms_thresh | FLOAT | 0.700–1 | — |
| crop_nms_thresh | FLOAT | 0.700–1 | — |
| crop_overlap_ratio | FLOAT | 0.340–1 | — |
| crop_n_points_downscale_factor | INT | 1 | — |
| min_mask_region_area | FLOAT | 0.000–1 | — |
| use_m2m | BOOLEAN | false | — |
| keep_model_loaded | BOOLEAN | true | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| mask | MASK | — |
| segmented_image | IMAGE | — |
| bbox | BBOX | — |