YOLO Segmentation (RMBG)
The one node in this pack that won't remove your background
- images
- background_color
- IMAGE
- ANNOTATED_IMAGE
- MASK
- MASK_LIST
Everything else in ComfyUI-RMBG answers "what is the foreground?" This node answers a different question: "where are the objects, and which one do you want?" That's YOLO - Ultralytics' real-time detector - wrapped so its instance masks come out as a ComfyUI mask you can actually wire somewhere. If you're used to reaching for SAM whenever a mask is involved, this is the cheaper, dumber, much faster option, and for "the person in this shot" it's usually enough.
What it's actually for
The job is targeted masking, not cutout. In the wider workflow that means: isolate a subject so you can inpaint only that, or run a detailer pass on it, or drop it into a composite with the background left alone. The KB's detection doc puts the distinction bluntly - the mask is the thing, and "you can get that mask in SO many ways."
Where YOLO beats the segmentation giants is vocabulary and speed. It knows. You don't prompt it, you don't click it. It has a fixed list of 80 everyday classes (the presets here are the standard COCO-trained seg weights), runs in milliseconds, and returns one mask per detected instance. For batch work across hundreds of frames that matters more than a beautiful edge.
Where it loses: anything not in those 80 classes. Your OC, your specific garment, your product - YOLO has no idea. That's when you go to the pack's SAM3 node or Florence-2, not here.
How it works
The node loads an Ultralytics -seg checkpoint and runs it per-image over the batch, then decides which of the returned instance masks you want. Two widgets do the picking, and confusing them is the number one way people get empty output:
mask_count- how many detections to merge.allmerges every instance; a number takes the first N.select_mask_index- 1-based start point. Onnoneit starts at the first detection.
The interaction is the fiddly part. select_mask_index on its own grabs one mask (the span defaults to 1 unless mask_count says otherwise), and select_mask_index: 3 + mask_count: 2 gives you detections three and four. Merging is a union - masks are combined with a max, so two overlapping boxes become one silhouette, never two outputs.
conf (0.25) and iou (0.45) go straight through to Ultralytics as-is. classes takes a comma list or ranges like 0,2,5-7 - class IDs, not names. annotation_mode only affects the preview image. retina_masks (on by default) is worth leaving on; it gives you high-res masks instead of postage stamps. device, max_det, agnostic_nms and unload_model are the knobs you'll only touch when something's wrong.
Inputs and outputs
Feed images - a batch, and it runs on every frame. Outputs:
- IMAGE - the cutout, RGBA when
backgroundisAlpha, RGB when you set aColor. - ANNOTATED_IMAGE - boxes and/or masks drawn on a copy. Free sanity check; wire it to a preview while you tune
conf. - MASK - the merged mask. This is the one you send to inpainting or a detailer.
- MASK_LIST - the same
MASKtype, but batched: one mask item per selected detection instead of one merged blob. Use it when instances need to be handled separately.
Wire MASK into VAEEncode-with-mask or any inpaint node; wire IMAGE into Image Save. If you only need the preview, don't bother loading the mask path at all.
Install
The node ships with the pack. In ComfyUI Manager search ComfyUI-RMBG, or:
cd ComfyUI/custom_nodes
git clone https://github.com/1038lab/ComfyUI-RMBG
./ComfyUI/python_embeded/python -m pip install -r ComfyUI-RMBG/requirements.txt
Then the optional bit, which the README is explicit about:
./ComfyUI/python_embeded/python -m pip install ultralytics --no-deps
ultralytics is deliberately not in requirements.txt. Install it --no-deps unless you enjoy watching it renegotiate your torch version. The preset weights download on first use into ComfyUI/models/ultralytics; drop your own .pt files in that folder and they appear in the model dropdown alongside the built-in presets.
Where people get burned
Ultralytics is AGPL-3.0, and the pack around it is GPL-3.0. That's a different licence planet from the MIT models the rest of ComfyUI-RMBG wraps, and it matters if you're shipping a product. Ultralytics has also had one genuine supply-chain incident - a poisoned release in December 2024 that shipped a cryptominer into ComfyUI setups through a detailing pack. Pin your version and don't blindly pip install -U it.
Two smaller ones, both from the code rather than the README:
- No detections produces a zero mask, not an error. Downstream inpainting then silently does nothing. Put
ANNOTATED_IMAGEon a preview while tuning, or you'll spend twenty minutes blaming the sampler. - Detection order is Ultralytics' confidence order.
select_mask_indexis not "left to right" or "biggest to smallest" - it's whatever the model ranked first. If you need stability across frames,mask_count: allis the honest choice.
Class IDs, not names. person typed into classes parses to nothing, prints a warning, and quietly keeps every class - so you get everyone in the shot and assume the filter is broken.
Inputs (18)
| Name | Type | Default | Description |
|---|---|---|---|
| images | IMAGE | — | |
| model | COMBO | yolo26m-seg (Medium / 54.8MB) | YOLO model weights stored under /tmp/ComfyUI/models/ultralytics (presets download automatically). |
| mask_count | COMBO | all | Merge this many detections. 'all' merges everything (or just the selected index when specified). |
| select_mask_indexopt | COMBO | none | 1-based index of the first mask to keep. Use 'none' to start from the first detection. |
| confopt | FLOAT | 0.250–1 | Confidence threshold forwarded to Ultralytics. |
| iouopt | FLOAT | 0.450–1 | IOU used during NMS. |
| classesopt | STRING | Comma list or ranges of class IDs; empty keeps every class. | |
| annotation_modeopt | COMBO | Mask & Box | Display mode for ANNOTATED_IMAGE output. |
| backgroundopt | COMBO | Alpha | Background type for cutout IMAGE output. |
| background_coloropt | COLORCODE | #222222 | Background color when background is set to Color. |
| mask_bluropt | INT | 00–64 | Apply Gaussian blur to mask edges. |
| mask_offsetopt | INT | 0-64–64 | Expand/Shrink mask boundary (positive = expand, negative = shrink). |
| invert_outputopt | BOOLEAN | false | Invert the mask output. |
| deviceopt | COMBO | auto | Force a device or auto-detect CUDA → MPS → CPU. |
| max_detopt | INT | 3001–1000 | Maximum detections per image. |
| retina_masksopt | BOOLEAN | true | Use high-resolution masks (Ultralytics retina_masks flag). |
| agnostic_nmsopt | BOOLEAN | false | Enable class-agnostic NMS. |
| unload_modelopt | BOOLEAN | false | Unload model from VRAM after execution. |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |
| ANNOTATED_IMAGE | IMAGE | — |
| MASK | MASK | — |
| MASK_LIST | MASK | — |