Nodes/ComfyUI-Grounding/Grounding Mask Detector
ComfyUI Node

Grounding Mask Detector

Skip the Boxes, Get the Exact Mask From a Sentence

By PozzettiAndrea·Created 10 months ago·Updated about 21 hours ago· 47
Grounding Mask Detector
  • model
  • image
  • masks
  • overlaid_mask
  • text
promptSegment the main object in the image
confidence_threshold0.30
florence2_max_tokens1024
florence2_num_beams3
sa2va_max_tokens2048
sa2va_num_beams1
seed42

Grounding Detector gives you a box and then you need a second node to carve the pixels out of it. This node skips all that: it runs models that output masks directly from your prompt, and if you load ByteDance's SA2VA it understands whole sentences, not just "dog" and "car". It's the closest thing in ComfyUI to just asking the image "who is that, and cut them out."

This is the mask-generation half of the pack, and SA2VA is its star. SA2VA is a vision-language model (based on Qwen3-VL) fine-tuned to produce SAM2 segmentation masks, so it can do the reasoning that classic detectors choke on - multiple characters in a scene, referring expressions like "the person in the red shirt holding the umbrella", even long paragraphs of description. Community reception when it hit ComfyUI was emphatic that it blows GroundingDINO-style pipelines away for semantic segmentation. The author built this pack partly to chain exactly these models against failure cases in background removal.

How it works

Two families live behind this node. Florence-2 (Base/Large) takes a descriptive phrase and generates masks plus annotations. SA2VA (1B/4B/8B/26B) takes an explicit instruction like Segment the person and returns masks, an overlay, and - uniquely - a text output describing what it did. Both come from the Grounding Mask Model (down)Loader. The node detects which family is loaded and routes accordingly, then hands you masks, an overlay preview, and text.

The inputs that matter

  • model + image - from the mask-model loader and your frame.
  • prompt - for Florence-2, a plain descriptive phrase; for SA2VA, be explicit: "Segment the person" rather than "person". The tooltip says it plainly, and SA2VA responds to instruction phrasing.
  • confidence_threshold - filters low-confidence masks where the model reports them.

Everything else is family-specific and ignorable until you're tuning: florence2_max_tokens / florence2_num_beams for Florence-2, sa2va_max_tokens / sa2va_num_beams for SA2VA (beam width 1 is the SA2VA default - keep it there unless you know why you're changing it), and seed for reproducible runs.

Outputs

  • masks - the actual segmentation, ready for inpainting, compositing, or cropping.
  • overlaid_mask - a visual preview to sanity-check before you commit.
  • text - SA2VA's description; a nice free side-channel if you're building agentic workflows that want a machine-readable answer about what was found.

Installing it

Same pack install, and the models auto-download from Hugging Face on first use:

cd ComfyUI/custom_nodes/
git clone https://github.com/PozzettiAndrea/ComfyUI-Grounding
cd ComfyUI-Grounding
pip install -r requirements.txt

Then restart ComfyUI (or install via Manager). Note the pack's install script also tries to set up flash_attn from a prebuilt wheel - it speeds up Florence-2/SA2VA inference and fails gracefully if your torch/CUDA combo doesn't have a matching wheel.

Where people get burned

  • SA2VA 26B is not a joke - that's a 26-billion-parameter VLM. Unless you have a serious card, the 1B and 4B variants are the practical ones. There's a sa2va_dtype option on the loader (auto/fp16/bf16/fp32) for squeezing them in.
  • Prompt style matters - reuse your GroundingDINO habit of terse labels and SA2VA will underperform. It wants instructions.
  • VRAM - these models are heavier than the box detectors. If you're also running Flux, flip keep_model_loaded off on the loader so the mask model offloads after each run.
  • First-run download lag - SA2VA weights are multi-GB; the first run looks hung but is just downloading.
Categorygrounding

Inputs (9)

NameTypeDefaultDescription
modelMASK_MODEL
imageIMAGE
promptSTRINGSegment the main object in the imageFor Florence-2: descriptive phrase. For SA2VA: explicit segmentation instruction (e.g., 'Segment the person')
confidence_thresholdFLOAT0.300–1Confidence threshold for mask filtering (where applicable)
florence2_max_tokensoptINT1024256–4096[Florence-2 only] Maximum tokens for generation
florence2_num_beamsoptINT31–5[Florence-2 only] Beam search width
sa2va_max_tokensoptINT2048512–8192[SA2VA only] Maximum tokens for generation
sa2va_num_beamsoptINT11–5[SA2VA only] Beam search width
seedoptINT420–4294967295Fixed seed for reproducible results

Outputs (3)

NameTypeDescription
masksMASK
overlaid_maskIMAGE
textSTRING