Sam2AutoSegmentation data
Kijai's auto-segmenter, plus the coordinates SAM2 video keying needs
- sam2_model
- image
- mask
- segmented_image
- bbox
- Color_list
- point_coords
This node is a modified copy of Sam2AutoSegmentation from kijai's ComfyUI-segment-anything-2 pack - same auto-segmentation behavior, with two extra outputs bolted on that the original doesn't give you: a color list and point coordinates per detected object. The author says so directly in the node's own description, and credits kijai by name for the original. If you already use SAM2's automatic mode to find every object in a frame with no prompting required, this is a drop-in replacement that also hands you the metadata needed for tracking those objects across video.
It's part of ComfyUI-WJNodes, a personal utility pack from an author publishing only as 807502278 - and this node is a good example of what that pack mostly is: small, targeted patches on top of other people's more established tools, built to fill a specific gap the author hit.
SAM2 (Meta's Segment Anything Model 2) extends SAM's segmentation into video, adding the ability to track a segmented object's mask across frames rather than just finding it in a single still. Its automatic mode - no click, no box, no text prompt - sweeps the whole image with a grid of sample points and returns a mask for everything it finds. That's genuinely useful, but the output on its own doesn't give you a clean way to identify "which mask is which object" across a sequence of frames, which is exactly the gap this node's extra outputs fill.
Inputs - the ones worth actually tuning
There are a lot of parameters here, most inherited straight from SAM2's automatic mask generator and best left at their defaults unless you have a specific reason to change them. The ones actually worth knowing:
- sam2_model - required, loaded through kijai's SAM2 pack, not this one. WJNodes provides no model loader for SAM2 itself.
- points_per_side - default 32. Controls the density of the sampling grid SAM2 sweeps across the image; higher catches smaller objects but costs more compute.
- pred_iou_thresh / stability_score_thresh - quality filters, both defaulting high (0.8 and 0.95). Raise them to keep only the most confident, stable detections and cut down noisy fragments; lower them if you're missing objects you expect to see.
- keep_model_loaded - on by default. Turn it off if you're tight on VRAM and running this alongside other heavy nodes, at the cost of reload time on the next run.
The rest - points_per_batch, mask_threshold, crop_n_layers, box_nms_thresh, crop_nms_thresh, crop_overlap_ratio, crop_n_points_downscale_factor, min_mask_region_area, use_m2m - are fine-tuning knobs for the underlying SAM2 auto-mask algorithm; leave them at default unless you're specifically fighting a segmentation quality problem.
Outputs that matter
Five outputs: mask and segmented_image work like the original SAM2 node - the detected masks and the segmented result. bbox gives bounding boxes for each detection. The two additions are Color_list and point_coords - per-object color identifiers and coordinate data, meant specifically to feed video-keying pipelines where you need a stable way to say "this mask in frame 1 is the same object as this mask in frame 40," which raw per-frame masks alone don't give you.
Installing it
Two packs required. WJNodes:
cd ComfyUI/custom_nodes
git clone https://github.com/807502278/ComfyUI-WJNodes.git
And kijai's ComfyUI-segment-anything-2, installed the same way - this node is useless without it, since that's where sam2_model and its loader come from. SAM2's own model weights (per the WJNodes README) land in models/sam2/ and download automatically the first time you need them.
Where people get stuck
If sam2_model has nothing to plug into, the issue is the SAM2 pack itself not being installed, not WJNodes - check for kijai's pack and its model loader node first. Beyond that, the auto-segmentation quality knobs are genuinely fiddly and there's no shortcut around testing them on your actual footage: an image with lots of small, similar objects close together needs different points_per_side and threshold values than a frame with a few large distinct subjects. This is a niche node from a pack with no public discussion trail, so lean on kijai's SAM2 documentation for the underlying parameter behavior, and treat WJNodes' README as the source only for what the two extra outputs are for.
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 (5)
| Name | Type | Description |
|---|---|---|
| mask | MASK | — |
| segmented_image | IMAGE | — |
| bbox | BBOX | — |
| Color_list | LIST | — |
| point_coords | LIST | — |