SamAutoMaskSEGSAdvanced
The SAM auto-mask knobs the plain version hides
- sam_model
- image
- masks_rle
SamAutoMaskSEGS runs SAM's automatic mask generator at fixed defaults. This is the same underlying process with every one of SAM's own tuning parameters exposed as node inputs - reach for it when the plain version is either too slow, missing objects it should catch, or picking up noise you don't want.
The dependency is the same as its sibling
Same requirement as SamAutoMaskSEGS: sam_model has to come from somewhere else - ComfyUI-Impact-Pack's SAMLoader or comfyui_segment_anything's SAMModelLoader, with HQ checkpoints only available through the latter, per the pack's README.
The inputs that actually matter
Most of the eleven optional parameters map straight onto Meta's own SAM automatic-mask-generator settings, each with its own tooltip in the node. You'll only ever touch a handful:
points_per_side(default 32) - how dense the grid of sample points across the image is; the real point count is this squared, so pushing it up finds finer detail at the cost of speed.points_per_batch(default 64) - how many of those points SAM evaluates at once. Higher is faster but eats more VRAM.pred_iou_thresh(default 0.88) andstability_score_thresh(default 0.95) - the two confidence filters. Masks scoring below either get thrown out. Lower them if SAM is finding real objects but discarding them; raise them if you're getting junk masks.min_mask_region_area(default 0, meaning off) - drop any detected region smaller than this many pixels. The easiest knob for cutting speckle/noise masks without touching the confidence thresholds.
The rest - stability_score_offset, box_nms_thresh, and the crop_n_layers / crop_nms_thresh / crop_overlap_ratio / crop_n_points_downscale_factor family for tiled, multi-pass detection on large or cluttered images - are fine left at their defaults unless you already know you need SAM's tiled-crop mode for images where objects are getting missed or duplicated.
The output is different from the plain version - worth noticing
This node hands back masks_rle (a single MASK_RLE), not the RLE_SEGS string SamAutoMaskSEGS produces, and it isn't marked as an output node - nothing gets automatically pushed into the API response. Decode it with this pack's RleToMask and feed it onward inside the graph, or wire your own output step if you want the result surfaced to a caller.
How to install it
cd ComfyUI/custom_nodes
git clone https://github.com/lldacing/comfyui-easyapi-nodes.git
cd comfyui-easyapi-nodes
pip install -r requirements.txt
Restart ComfyUI, then set up a SAM loader pack (Impact Pack or comfyui_segment_anything) separately if you haven't already - this pack only provides the node, not the model.
Common issues & troubleshooting
The slowness caveat from the plain version applies here too, amplified. Cranking points_per_side up or turning on crop_n_layers for tiled detection both trade real time and VRAM for better coverage - change one knob at a time and watch what it costs before stacking several together.
If tuning thresholds doesn't seem to change anything, check that sam_model is actually connected to a loaded checkpoint and not left on a stale or disconnected wire - an easy mistake when copying this node in from a template workflow.
Inputs (14)
| Name | Type | Default | Description |
|---|---|---|---|
| sam_model | SAM_MODEL | — | |
| image | IMAGE | — | |
| points_per_sideopt | INT | 321–16384 | 沿图像一侧采样的点数。 总点数为points_per_side的平方。优先级盖玉point_grids, 如果为 None,则 'point_grids'采样点必须传 |
| points_per_batchopt | INT | 641–16384 | 设置模型同时执行的点数。 数字越大,速度越快,但会占用更多的 GPU 内存 |
| pred_iou_threshopt | FLOAT | 0.880–1 | 置信度阈值。 置信度低于此值的掩码将被忽略 |
| stability_score_threshopt | FLOAT | 0.950–1 | 稳定性得分的过滤阈值,范围[0,1] |
| stability_score_offsetopt | FLOAT | 1.000–1 | 计算稳定性得分时thresh偏移量。 公式简单理解成 score= (mask > stability_score_thresh+stability_score_offset) / (mask > stability_score_thresh-stability_score_offset) |
| box_nms_threshopt | FLOAT | 0.700–1 | mask的bbox区域置信度阈值 |
| crop_n_layersopt | INT | 00–64 | 递归重复检测层数,增大此值可以解决多个物体没拆分开的问题,但是速度会变慢 |
| crop_nms_threshopt | FLOAT | 0.700–1 | crop_box区域置信度阈值 |
| crop_overlap_ratioopt | FLOAT | 0.340–1 | 多层检测时,设置裁剪重叠的程度,第一层使用此值。随着层数增加,重叠程度会减小 |
| crop_n_points_downscale_factoropt | INT | 11–16384 | 用于计算第n层的points_per_side:int(points_per_side/crop_n_points_downscale_factor**n) |
| min_mask_region_areaopt | INT | 00–16384 | 最小区域面积。 用于过滤(忽略)小区域 |
| output_modeopt | COMBO | uncompressed_rle | 2 options: uncompressed_rle, coco_rle |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| masks_rle | MASK_RLE | — |