Prompt SEGS w/ SAM
GroundingDINO finds it, SAM masks it, negative prompts subtract it
- image
- sam_model
- grounding_dino_model
- vitmatte_model
- segs
- mask
This is the node people mean when they say "Grounded SAM" in ComfyUI: type "person" or "cat" or "red jacket", and it finds every matching thing in the image, cuts it out along its actual outline, and hands you the regions as SEGS. SimpleSyrup.PromptSEGSWithSAM does that in one node - GroundingDINO does the text-driven detection, SAM turns the boxes into precise masks - and then layers on two things the plain version doesn't give you: a negative prompt, and proper edge refinement.
Why it's the star of the pack's detection cluster: it's the node that turns natural language directly into detailer input. No YOLO weights, no class files. The whole point of text-driven detection is that "find the faces" and "find the logo" and "find the cups on the table" are the same workflow with a different string.
The pipeline, from the tooltips and the source: your positive_prompt goes to GroundingDINO, which returns boxes that score above confidence_threshold (default 0.3). Boxes can be grown or shrunk with bbox_dilation before SAM sees them. SAM generates a mask for each box. Then the negative_prompt is subtracted - regions matching text you don't want get removed from the detected area - and the surviving masks can be dilated (mask_dilation), edge-refined, and trimmed (size_threshold, keep_only / keep_by).
The two parts of this that trip people up, and what to do:
- Confidence vs. recall.
confidence_thresholdat 0.3 is a reasonable middle. Raise it toward 0.5 if you're getting junk detections; lower it if you're missing things. GroundingDINO is permissive, so most people tune down, not up. - Edge refinement is on by default (
refine_masktrue, methodGuidedFilter,detail_erode6,detail_dilate6). This is what keeps your masks from looking like SAM's default wobbly edges. It costs time on big images, hencemask_refinement_max_size(default 2048) bounding the working size, andexecution_device(autovs forcingCPUto dodge GPU memory pressure). If you have a ViTMatte model, the optionalvitmatte_modelinput unlocksVITMatteas adetail_method- the highest-quality edge option, at the cost of another model.
On the output side you get segs and mask. mask is the combined prompted area as a standard ComfyUI mask - that alone is worth the node if you've ever tried to build a "mask everything that's a person" mask by hand. And because these SEGS are Impact-compatible, the regions flow straight into FaceDetailer-style detailing, the pack's regional samplers, or tiled diffusion contexts.
The negative prompt is the sleeper feature. Want "person" but not "person wearing a hat"? That's the difference between detections you have to manually prune and detections that arrive pre-pruned.
Install: the pack:
cd ComfyUI/custom_nodes
git clone https://github.com/Artificial-Sweetener/SimpleSyrup
cd SimpleSyrup && pip install -r requirements.txt
or ComfyUI Manager → search SimpleSyrup → Install → restart, with current ComfyUI (v3 extension API). This node needs a GroundingDINO model and a SAM model - the pack's own Load Ultralytics Model, SAM Model Loader, and a GroundingDINO loader provide them, and the downloadable-models setting can fetch known catalog entries for you. Models are the usual source of "it doesn't work": no detections → check the confidence threshold and that the prompt names something actually in the image; weird mask edges → leave refinement on and stop cranking detail_erode past what the mask needs.
Inputs (23)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | Image to search with the text prompt. | |
| sam_model | SAM_MODEL | SAM model used to create masks for the prompted boxes. | |
| grounding_dino_model | GROUNDING_DINO_MODEL,DINO_MODEL | GroundingDINO model used to find boxes that match the prompt. | |
| positive_prompt | STRING | Text describing the regions to detect. | |
| negative_prompt | STRING | Text describing areas to subtract from the detected regions. | |
| confidence_threshold | FLOAT | 0.300–1 | Minimum GroundingDINO confidence required to create a SAM prompt box. |
| size_threshold | INT | 101–8192 | Discard final regions whose mask bounds are smaller than this many pixels wide or tall. |
| keep_only | INT | 00–4096 | Keep only this many detected regions after threshold filtering. Use 0 to keep all regions. |
| keep_by | COMBO | highest confidence | Choose how regions are ranked when Keep Only is greater than 0. |
| bbox_dilation | INT | 0-512–512 | Grow or shrink prompt boxes in pixels before sending them to SAM. |
| mask_dilation | INT | 0-512–512 | Grow or shrink each final region mask in pixels after prompt subtraction. |
| detail_method | COMBO | GuidedFilter | Method used to refine mask edges. |
| detail_erode | INT | 60–255 | Pixels trimmed inside the mask edge during refinement. Higher values pull the refined edge inward. |
| detail_dilate | INT | 60–255 | Pixels added outside the mask edge during refinement. Higher values give refinement more outside context. |
| black_point | FLOAT | 0.150–0.98 | Mask values at or below this become black. |
| white_point | FLOAT | 0.990.02–1 | Mask values at or above this become white. |
| refine_mask | BOOLEAN | true | Enable edge refinement for the final masks. |
| mask_refinement_max_size | INT | 20481–16384 | Maximum working size for mask refinement. Larger images are refined at a bounded size for performance. |
| execution_device | COMBO | auto | Device for model-backed refinement. Auto uses normal ComfyUI placement; CPU avoids GPU memory pressure. |
| crop_factor | FLOAT | 3.01–100 | How much context to include around each prompted region. Higher values make larger SEG crops. |
| sort_order | COMBO | largest to smallest | Order the returned SEGS before output and before the combined mask is built. |
| combine_segs | BOOLEAN | false | Return one unioned SEGS region instead of separate regions. |
| vitmatte_modelopt | VITMATTE_MODEL | Optional ViTMatte model used when detail_method is VITMatte. |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| segs | SEGS | Prompted regions as separate or combined SEGS based on combine_segs. |
| mask | MASK | Combined prompted area as a standard ComfyUI mask. |