LayerMask: SegmentAnythingUltra V2.1
SegmentAnythingUltra V2.1 — mask anything by typing what it is
- image
- image
- mask
Type "the red dress" or "logo" or just "subject," and this node hands you a mask around it - no brush, no lasso, no clicking points on the canvas. That's the whole pitch: it's GroundingDINO and Segment Anything wired together into one node, which is the standard combo for targeted masking - picking out one specific object rather than just splitting foreground from background. If you've ever wanted to select "the watch" and nothing else in a product photo, this is the tool for that job, not a plain background remover.
This particular copy is carried over from chflame163's ComfyUI_LayerStyle (the dzNodes prefix in the category is the tell), and the V2.1 in the name isn't decorative - the author of this fork specifically fixed a bug where processing a batch of images would just stop dead the moment one frame errored out, instead of skipping it and continuing. If you're running this over folders of images rather than one at a time, that's the reason this version exists.
How it works
GroundingDINO is a text-prompted object detector: give it a phrase, it hands back a bounding box. SAM (Segment Anything) turns that rough box into a pixel-accurate mask. Together they cover the gap plain background-removal tools can't: those only know foreground versus background, this knows "the thing you named." After SAM produces its mask, the node runs a second, optional detail pass to soften the hard segmentation edge into something closer to real alpha - useful anywhere a mask has stray hairs, blur, or a soft boundary that a binary cutout would butcher.
The inputs and outputs that matter
prompt(default"subject") - what to look for, in plain text. Change this to name the actual object you want isolated.sam_modelandgrounding_dino_model- checkpoint choices. SAM spansmobile_sam(39MB, fast, less precise) up tosam_hq_vit_h(2.57GB, highest quality); GroundingDINO offers the smaller SwinT_OGC or the more accurate SwinB. Bigger means slower and hungrier for VRAM.threshold(default 0.3) - DINO's detection confidence cutoff. Raise it if it's grabbing things you didn't ask for, lower it if it's missing the object.detail_method- how the edge gets refined after the raw SAM mask: VITMatte (the modern neural default, plus a(local)variant that stays on your own GPU), PyMatting (lighter, non-neural), or GuidedFilter (fastest, roughest).process_detailtoggles this whole pass off if you just need a rough mask fast.detail_erode/detail_dilateandblack_point/white_point- shrink/grow the mask and adjust matte contrast before the detail pass; defaults are sane.deviceandmax_megapixels- downsamples large images before detection, which matters more than it sounds like on a batch of full-res photos.
Outputs are image and mask - the mask is what you'll actually wire onward, typically into an inpaint or LaMa node to fill in what you just isolated, or into a compositing node to cut it out cleanly.
How to install it
ComfyUI Manager: search HFDownLoad Node for ComfyUI, install, restart. Manual: cd ComfyUI/custom_nodes && git clone https://github.com/icesun963/ComfyUI_HFDownLoad, then restart.
The dropdown values literally show you the file sizes (sam_vit_h (2.56GB), mobile_sam (39MB)) - that's your cue these are real checkpoints that need to exist on disk before the node will run, and nothing here auto-fetches them for you. This same pack ships HFDownLoad_Tool for exactly that reason: point it at the right HuggingFace repo and download folder to get the SAM and GroundingDINO weights in place.
Common issues & troubleshooting
Empty dropdowns. If sam_model or grounding_dino_model shows nothing to pick, the folder ComfyUI scans for those checkpoints is empty - go download the matching file, matching the exact name shown (including the size, so you know you got the right one).
It grabs the wrong thing, or nothing at all. This is almost always prompt or threshold. Be specific in the prompt ("the watch on the wrist," not just "watch" if there are several objects); nudge threshold down if it's missing an obvious match, up if it's too trigger-happy on similar-looking objects.
Batch runs used to die on one bad frame. That was the bug this V2.1 fork patched - if you're still seeing a whole batch abort because of a single problem image, you're likely not on this fixed version.
It's doing the same job as tools elsewhere in the ecosystem. ComfyUI's Impact Pack also ships SAM-based detection, and fatter bundles like ComfyUI-RMBG now wrap SAM3 and GroundingDINO together too. None of that makes this node wrong to use - it's just worth knowing you're not stuck with it if a workflow you're copying assumes a different pack.
Inputs (13)
| 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_method | COMBO | 4 options: VITMatte, VITMatte(local), 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 | — |