SAM3 Segment (NH)
Name a thing, get every one of them
- image
- segs
- mask
- count
- report
For two years the standard way to mask "all the windows in this building" was a two-model chain: GroundingDINO to detect boxes from text, SAM to mask inside each box, then glue nodes. SAM 3 collapsed that - a short noun phrase returns masks for every matching instance in one pass, which is why it's the most talked-about addition to ComfyUI masking since SAM itself.
SAM3 Segment is the NH-Nodes wrapper, and it's a generous one: you type what you want, it finds every instance, shows you what it found on the node, and hands the instances to the pack's Segs nodes for finer picking.
Why this node over the other maskers
It handles anything you can name. Background-removal models are built for foreground-versus-background and get vague on hair and fur; they're the wrong tool for "the sky" or "the shirt but not the jacket". SAM 3 is a concept segmenter, not a matte model.
It's good on big photos. The model itself sees about 1000 px, so on a 4K-to-8K shot a window would come out soft - balanced mode fixes that by segmenting each instance a second time on a close-up cut from the full-resolution original.
And it keeps instances separate: three people are three instances with their own labels, scores and boxes, not one union mask. That's what lets you build "the second person from the left" out of Segs Select.
The honest caveat: hair, lace and fur won't be perfect. SAM 3 describes whatever it looks at on a grid of roughly 288 cells, so a subject filling an 8K frame has edges accurate to about 1/300 of its size - fine for an outline, soft on flyaway hair.
The inputs
concepts is the node. Short English words - person, window, red car - plus the pack's formula language:
| Write | You get |
|---|---|
| person, hair | a list - the union of both |
| person - bag | people without the bags |
| a & b | only where both are |
| ~person | everything except people |
| background | everything outside whatever was found |
| (wall \| ceiling) - window | a facade with the openings cut out |
Commas or new lines list, parenthesise freely, and put spaces around a minus - person-hair is one label and errors. Common Vietnamese words translate (tóc is hair, nền is background), and labels come back in English, so downstream matching stays plain.
threshold (0.05–0.95, default 0.5) is the dial you'll touch constantly. Lower finds more and invents more; higher keeps only what it's sure of. The report output is what makes that bearable: when a concept finds nothing it says whether there were no candidates at all or the best one scored just under your threshold, which is a completely different fix.
detail_level - leave it on balanced. fast skips the per-instance close-up pass and is for small images and for hunting the right word.
max_per_concept (0 keeps all) caps instances per concept, best score first. checkpoint picks the .pt from models/sam3. keep_model_loaded holds 3.6 GB of weights on the GPU between runs - faster, but ComfyUI can't use that VRAM meanwhile and Unload Models won't free it.
Outputs: segs (the instances), mask (your formula's result, per image), count and report.
Installing it - the part nobody warns you about
The node installs with the pack: ComfyUI Manager, search NH-Nodes, install, restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/jetthuangai/NH-Nodes.git
cd NH-Nodes
python -m pip install -r requirements.txt
SAM 3 is not in that. NH-Nodes installs none of it and downloads none of it, because Meta's licence requires you to accept terms first. Three things are on you.
An NVIDIA GPU with CUDA. No CPU mode and no device input - official sam3 code builds part of the model on the GPU, so there's nothing to fall back to. About 5 GB of VRAM at peak.
Meta's sam3 package, into the Python that runs ComfyUI, then restart:
python -m pip install --no-deps git+https://github.com/facebookresearch/sam3@b26a5f330e05d321afb39d01d3d4881f258f65ff
python -m pip install timm ftfy regex iopath
The first line pins the commit the pack was tested against, and --no-deps is deliberate: sam3 asks for numpy below 2, which ComfyUI doesn't want. Upstream wants Python 3.12+, PyTorch 2.7+ and CUDA 12.6+.
The checkpoint. Accept the SAM License at huggingface.co/facebook/sam3, download sam3.pt, drop it in ComfyUI/models/sam3/, press R to refresh.
Common issues
The safetensors file doesn't work. Hugging Face also hosts safetensors exports built for the transformers library, with different weight names. This node wants the PyTorch .pt.
Another SAM 3 pack is already installed. Then the package and checkpoint are probably in place - they share folders. Don't reinstall sam3 over the other pack's copy.
It runs when you don't want it to. It's an output node: ComfyUI runs it with nothing connected, and show_preview off doesn't stop it. Mute or delete abandoned copies.
Everything looks like the whole picture. A list is a union: person, background is a person plus everything outside them - the full frame. Ask for background alone.
Setup failures are errors with instructions. Missing package, a package that won't load, missing checkpoint, wrong checkpoint, no CUDA - the message names the fix.
Inputs (8)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| concepts | STRING | person | What to find, in short English words (person, red car, window, sky); common Vietnamese words work too (tóc, váy, túi, nền). Commas or new lines list several. The mask follows the formula: person - bag (minus), hair + face (plus), ~person (everything else), background (everything outside what was found; people are searched for it), shirt & jacket (overlap), parentheses. |
| threshold | FLOAT | 0.500.05–0.95 | Minimum confidence. Lower finds more (and more mistakes), higher keeps only sure ones. The report says how close a concept that was not found came. |
| detail_level | COMBO | balanced | balanced: each instance is segmented again on a close-up cut from the full-resolution image, so small and medium objects get crisp edges even on 4K-8K pictures (about 0.1 s per instance on a fast GPU). A subject filling most of the frame keeps edges at about 1/300 of its size. fast: one look at the whole image only. |
| max_per_concept | INT | 00–200 | Keep at most this many instances of each concept, best first. 0 keeps all. |
| checkpoint | COMBO | SAM 3 checkpoint in models/sam3 (shared with other SAM 3 packs). Download sam3.pt from huggingface.co/facebook/sam3 after accepting Meta's license. | |
| keep_model_loaded | BOOLEAN | false | Keep SAM 3 on the GPU after the run (about 3.6 GB): faster when it runs again, but ComfyUI cannot use that VRAM meanwhile, and its Unload Models button does not release it (turn this off and run the node once, or restart ComfyUI). |
| show_previewopt | BOOLEAN | true | Show the mask (bright), the instances found (outlined and labelled) and the report on the node itself. The node runs even with nothing connected. |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| segs | NH_SEGS | — |
| mask | MASK | — |
| count | INT | — |
| report | STRING | — |