Nodes/ComfyUI-CustomNodePacks/SAM Multi-Mask Picker — 3 candidates + scores
ComfyUI Node

SAM Multi-Mask Picker — 3 candidates + scores

SAM gives you three masks — see all of them and click the right one

By Code2Collapse·Created 6 months ago·Updated a day ago· 52
SAM Multi-Mask Picker — 3 candidates + scores
  • image
  • sam_model
  • bbox
  • selected_mask
  • all_masks
  • selected_index
  • scores
  • info
model_namesam2.1_hiera_base_plus
points_json[{"x": 256, "y": 256, "label": 1}]
bbox_json
precisionfp32
selected_index0

Here's the SAM experience every newcomer has: you click a point, and the model returns three masks - one tight, one loose, one that grabbed half the background - ranked by confidence, and you're supposed to know which mask_index to take. The community's answer is exactly what this node is: stop guessing, show all three, let the human pick. SAM Multi-Mask Picker (MEC) runs the inference and then puts the three candidates in front of you as clickable thumbnails with their confidence scores, so the choice is visual instead of blind.

How the picking works

How it works is two parts. Underneath, it's a full SAM inference - image in, a point prompt in points_json (default [{"x":256,"y":256,"label":1}]) and/or a box in bbox_json, and SAM's mask decoder returns its standard three candidates. On top, a JS widget renders a thumbnail of each mask overlaid on your image; you click one or press 1/2/3 to select it, and selected_index updates to match. Press R and it re-runs with fresh prompts. The pick lands on selected_mask, and all_masks carries all three as a stack so you can inspect them downstream. scores is a comma-separated confidence list - visible proof of why you shouldn't have trusted mask 0 by default.

Where the model comes from

The model comes from a model_name dropdown (it auto-lists whatever SAM weights are in your models folders, with sam2.1_hiera_base_plus as the default - bigger models = better quality, more VRAM), or you can plug in a pre-loaded model from SAMModelLoaderMEC via the sam_model input, which overrides model_name. Same for prompts: bbox from an upstream BBox node overrides bbox_json. precision (default fp32, with fp16/bf16 for VRAM) is worth dropping on a tight card.

Which SAM generation you're on

One nuance: the brief and the source agree this node's lineage is the older SAM1/SAM2/HQ-SAM generation - it says it works with SAM1, SAM2, and HQ-SAM, which means it's the "pick visually" tool for the classic promptable SAM workflow, while the newer pack nodes (Mask Generator, the ViTMatte pipeline) are the SAM 2.1/3 line. Don't let that scare you: the candidate-picking problem is identical across generations, and if you're on the classic SAM weights this is the right UI. If you're on 2.1/3, the SamMultiMaskPickerMEC still accepts a pre-loaded sam_model from the loader, so you get the picker UI with modern weights.

Outputs and install

Outputs: selected_mask, all_masks, selected_index, scores, info (JSON of prompts, scores, selection). Feed selected_mask into an inpaint mask, a matting node, or a detail pass - the whole point is that downstream work starts from the candidate you actually meant.

Install is the pack: clone Code2Collapse/ComfyUI-CustomNodePacks into custom_nodes (or Manager → "CustomNodePacks") plus the SAM runtime and weights (models/sam2/, models/sams/) and pip install git+https://github.com/facebookresearch/sam2.git for the 2.1 line. It's the node the README frames as "tired of SAM giving 3 masks and not knowing which one to pick" - and honestly, that's most of us.

CategoryC2C/SAM

Inputs (8)

NameTypeDefaultDescription
imageIMAGEInput image (B, H, W, C) float32 [0, 1]. First frame used for inference.
model_nameCOMBOsam2.1_hiera_base_plusSAM model variant to use for inference. Larger models = better quality, more VRAM.
points_jsonSTRING[{"x": 256, "y": 256, "label": 1}]JSON array of point prompts: [{"x":100,"y":200,"label":1}, ...]. label=1=foreground, label=0=background.
bbox_jsonSTRINGOptional bounding box as JSON: [x1, y1, x2, y2]. Leave empty to use only point prompts.
precisionCOMBOfp32Model precision. fp16/bf16 use less VRAM but may reduce quality on some GPUs.
selected_indexINT00–2Which of the 3 candidate masks to output (0-2). Updated by JS widget on click/keyboard.
sam_modeloptSAM_MODELPre-loaded SAM model from SAM Model Loader node. Overrides model_name if connected.
bboxoptBBOXBounding box from BBox node (overrides bbox_json).

Outputs (5)

NameTypeDescription
selected_maskMASKMask chosen by the user (or selected_index input).
all_masksMASKStack of all 3 SAM candidate masks.
selected_indexINTIndex of the currently picked mask.
scoresSTRINGComma-separated SAM confidence scores for each candidate.
infoSTRINGJSON summary of prompts, scores, and selection.