LayerMask: SegmentAnythingUltra V3(Advance)
SegmentAnythingUltra V3 — same masking, but the models load once
- image
- sam_models
- image
- mask
V3 does exactly what V2 does - text-prompted segmentation via Grounding DINO + SAM, with an edge-refinement pass on top - but it fixes a real inefficiency in how the models get loaded. In V2, sam_model and grounding_dino_model are dropdowns right on the node, which means every SegmentAnythingUltra node in your graph loads its own copy of both models. If you've got three of these nodes going after different objects in the same workflow, that's three redundant SAM loads eating VRAM and startup time for no reason. V3 splits model loading into a separate node (LayerMask: Load SegmentAnything Models) and takes the result as a single sam_models input instead - load once, reuse everywhere.
Everything downstream of that split is identical to V2: threshold (default 0.3) is Grounding DINO's detection confidence for matching your prompt text; prompt defaults to "subject" but works with any noun phrase you want it to find and mask. detail_method picks the edge-refinement technique (VITMatte for the best hair/fur quality at real memory cost, PyMatting/GuidedFilter as lighter alternatives), detail_erode/detail_dilate shrink or grow the mask boundary, black_point/white_point are the edge-sampling thresholds, process_detail toggles the whole refinement pass, device picks where that refinement runs, and max_megapixels caps resolution for the VITMatte pass specifically. Outputs are image and mask, same as V2.
The practical reason to reach for V3 over V2: if you're only ever running one segmentation node per workflow, V2 is simpler and there's no real downside. But the moment you need SAM to find two or three different things in the same image - say, masking a person and a specific prop separately - V3 with a shared LayerMask: Load SegmentAnything Models node upstream means you're not paying the SAM/DINO load cost multiple times over.
Install through ComfyUI Manager (search "ComfyUI Layer Style Advance") or git clone https://github.com/chflame163/ComfyUI_LayerStyle_Advance into custom_nodes/, restart, run the requirements installer. Model requirements are the same as V2: SAM checkpoints in ComfyUI/models/sams, Grounding DINO config + weights in ComfyUI/models/grounding-dino, and - the one people miss - Grounding DINO's tokenizer needs the five bert-base-uncased files (config.json, model.safetensors, tokenizer_config.json, tokenizer.json, vocab.txt) in ComfyUI/models/bert-base-uncased. All of it is bundled together on chflame163's HuggingFace repo. If you're using VITMatte for edge detail, grab that model into ComfyUI/models/vitmatte too.
The bert-base-uncased requirement is worth flagging specifically because it's the most common way this whole node family breaks: it's fetched from Hugging Face at load time if it isn't already cached, so on any offline, firewalled, or sandboxed deploy - people have hit this trying to containerize ComfyUI for hosting - you'll get a couldn't connect to huggingface.co error the instant Grounding DINO tries to build its tokenizer, even though the SAM and DINO checkpoints themselves are already sitting locally. Pre-downloading those five files avoids it entirely. Beyond that, a cv2.ximgproc guidedFilter error means a bad opencv-contrib-python version - repair_dependency.bat in the plugin folder fixes the handful of dependency-version issues automatically.
Inputs (12)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| sam_models | LS_SAM_MODELS | — | |
| threshold | FLOAT | 0.300–1 | — |
| detail_method | COMBO | 5 options: VITMatte, VITMatte(local), vitmatte-base-composition-1k, PyMatting, GuidedFilter | |
| detail_erode | INT | 61–255 | — |
| detail_dilate | INT | 61–255 | — |
| black_point | FLOAT | 0.150.01–0.98 | — |
| white_point | FLOAT | 0.990.02–0.99 | — |
| process_detail | BOOLEAN | true | — |
| prompt | STRING | subject | — |
| device | COMBO | 2 options: cuda, cpu | |
| max_megapixels | FLOAT | 2.01–999 | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| mask | MASK | — |