LayerMask: SegmentAnythingUltra(Advance)
Text-prompted SAM + GroundingDINO, with sharper edges bolted on
- image
- image
- mask
The classic text-prompted masking combo - GroundingDINO finds the object from a text description, SAM turns that into a precise segmentation - packaged as one node, with an edge-refinement pass on top that the plain version of this workflow doesn't give you. SegmentAnythingUltra is an improvement on storyicon/comfyui_segment_anything; what LayerStyle Advance adds is the same matting-style detail pass used across its "Ultra" node family, so instead of SAM's often-blocky default mask you get something closer to production-ready on hair and fine edges.
This is the heaviest-to-install node in this batch, model-wise, so budget time for the download before your first run.
How it works
You type what you want in prompt (default "subject") - GroundingDINO locates candidate regions matching that description, SAM turns each into a mask, and the node's own edge pass refines the boundary. This is exactly the two-stage pipeline the wider community reaches for when a plain background-remover (BiRefNet, rembg) isn't precise enough because you need a specific object, not just "the foreground."
The inputs and outputs that matter
image/prompt- required.promptis a plain-text description of what to segment, not a fixed category list.sam_model- seven choices, frommobile_sam(39MB, fast, lower quality) up tosam_vit_hand the HQ variants (2.5GB+, slow, best quality). Pick based on how much you're willing to wait.grounding_dino_model-GroundingDINO_SwinT_OGC(694MB) orGroundingDINO_SwinB(938MB).threshold(default 0.3) - GroundingDINO's detection confidence cutoff. Lower it if it's missing things it should find; raise it if it's grabbing false positives.detail_range(default 16, range 1–256) - the edge-refinement span. Note this node uses a singledetail_rangeknob rather than the separate erode/dilate pair you'll see on other Ultra nodes (BenUltra, Florence2Ultra) - different edge-processing implementation, same general idea.black_point(0.15) /white_point(0.99) - edge sampling thresholds.process_detail(default on) - disable to skip refinement and just take SAM's raw output.cache_model(default off) - keep the models resident between runs instead of reloading each time; worth turning on if you're running this node repeatedly in the same session.
Outputs are image and mask.
Installing it
ComfyUI Manager: search "ComfyUI Layer Style Advance". Manual:
cd ComfyUI/custom_nodes
git clone https://github.com/chflame163/ComfyUI_LayerStyle_Advance.git
Run install_requirements.bat (portable) or install requirements.txt yourself, then restart.
Then the model downloads, and there are several: bert-base-uncased (5 files - config.json, model.safetensors, tokenizer files - into ComfyUI/models/bert-base-uncased), your chosen GroundingDINO config + weights (into ComfyUI/models/grounding-dino), and your chosen SAM checkpoint(s) (into ComfyUI/models/sams). The README's combined HuggingFace/BaiduNetdisk links cover all of it if you don't want to hunt down each piece separately.
Common issues
Node errors about a missing BERT model. GroundingDINO's text encoder needs the bert-base-uncased files specifically - it's easy to grab the SAM and GroundingDINO weights and forget this one, since it's not obviously "part of" either model by name.
Detection misses the object entirely. Lower threshold first. If that doesn't help, the prompt wording matters more than you'd expect - GroundingDINO responds better to simple noun phrases ("the red bag") than long descriptive sentences.
Very slow on first run. sam_vit_h and the HQ variants are genuinely large models; if speed matters more than maximum edge quality, drop to sam_vit_b or mobile_sam and compare - the quality gap is real but often smaller than the speed gap.
Loading the model every single run. Turn on cache_model if you're iterating in the same session - it's off by default, which means a fresh load (and fresh VRAM allocation) every execution otherwise.
Inputs (10)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| sam_model | COMBO | 7 options: sam_vit_h (2.56GB), sam_vit_l (1.25GB), sam_vit_b (375MB), sam_hq_vit_h (2.57GB), sam_hq_vit_l (1.25GB), sam_hq_vit_b (379MB), +1 | |
| grounding_dino_model | COMBO | 2 options: GroundingDINO_SwinT_OGC (694MB), GroundingDINO_SwinB (938MB) | |
| threshold | FLOAT | 0.300–1 | — |
| detail_range | INT | 161–256 | — |
| black_point | FLOAT | 0.150.01–0.98 | — |
| white_point | FLOAT | 0.990.02–0.99 | — |
| process_detail | BOOLEAN | true | — |
| prompt | STRING | subject | — |
| cache_model | BOOLEAN | false | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| mask | MASK | — |