Segformer B2 Clothes Ultra-Fast
The fastest way to mask clothes (or a whole person) in ComfyUI
- image
- labels
- image
- mask
You know the drill: you want to inpaint a jacket, swap a shirt, isolate a person for compositing - and the bottleneck is always the same. You either hand-draw a mask or pull in a heavyweight SAM model and wait. Segformer B2 Clothes Ultra-Fast is the pack's answer to both: a semantic segmentation model that runs on whole batches - video frames included - and turns them into clean, per-pixel masks in seconds. It's the workhorse this pack exists for.
What it actually does
Under the hood it's mattmdjaga/segformer_b2_clothes, a HuggingFace AutoModelForSemanticSegmentation checkpoint (there are three alternates in the dropdown). Each image is classified pixel-by-pixel into clothing and body-part classes - hat, hair, upper clothes, pants, dress, left arm, right leg, shoe, background - and the node compares that class map against the labels list you feed it, then inverts the result into a mask. The trick that makes it "ultra fast" is that it processes the batch in chunks of batch_size and does everything in tensor ops on a single model forward pass, so it's genuinely video-friendly - wire a frame batch in and you get a mask per frame.
Here's the part that trips everyone up, and it's worth getting straight: the labels input is the list of classes to punch out of the mask. The output is white where a pixel's class is not in that list. That's why the label nodes use checkboxes - tick a box and that class stays in the mask. Leave everything unchecked and the mask comes out solid black, which reads as "broken" until you realize you simply haven't asked for anything yet.
The inputs that matter
image- your image or batch of frames. Works fine on CPU for a single image; bumpdeviceto your GPU for video.labels- a wildcard*input. Feed it from a matching Label node:Segformer Clothes Labelfor the b2/b3-clothes models,Segformer Fashion Labelfor the b2/b3-fashion models. Mixing them up gives garbage masks, because the two label sets don't share class ids.model- four choices, defaulting tomattmdjaga/segformer_b2_clothes. The b3 variants are a touch more accurate and slower; the fashion variants are for fine garment details.process_detailanddetail_method- edge refinement.VITMatte_fast(the default) runs a second, small matting model on a trimap to get soft hair and fabric edges;VITMatteis the same but slower and marginally better;GuidedFilterskips the extra model entirely;PyMattinguses thepymattinglibrary, which is not in the pack's requirements - pick it and you'll likely crash until youpip install pymatting.max_megapixels,black_point/white_point,expand_mask- resolution cap for the matte stage, alpha contrast remap, and a final grow/shrink on the mask.
Outputs
Two: image and mask. The image output is your original composited with the mask as an alpha channel (RGBA) - handy for previewing the cutout directly. The mask output is the one you'll actually wire into inpainting, compositing, or a Mask To Bbox (SAM2) node for downstream work.
Installing it
The pack is lihaoyun6/ComfyUI-Segformer_Ultra_Fast. Easiest path: ComfyUI Manager → search "Segformer Ultra Fast" → Install → restart. Or by hand:
cd ComfyUI/custom_nodes
git clone https://github.com/lihaoyun6/ComfyUI-Segformer_Ultra_Fast
Its requirements.txt is transformers>=4.54.0, huggingface_hub, numpy, kornia, pillow - kornia is the unusual one (it powers the morphology and blur ops). On first run the segformer model downloads itself into ComfyUI/models/segformer/, and if you use a VITMatte detail method it grabs hustvl/vitmatte-small-composition-1k into models/vitmatte/, so expect a wait and some disk the first time. The author, lihaoyun6, is the same person behind the well-liked FlashVSR_Ultra_Fast video upscaler, so this isn't a one-off throwaway repo.
Common issues
- All-black mask - all label checkboxes are off. Tick what you want to keep.
- Wrong label node for the model - the two label nodes map to different class sets; match them to the model you selected.
PyMattingcrash - needspymattinginstalled manually.- Slow first run - that's the model download, not a hang.
For a batch-aware mask utility to pair with this, the same pack ships GrowMask Ultra-Fast, and Mask To Bbox (SAM2) turns the result into crop boxes for refinement passes.
Inputs (14)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| labels | * | — | |
| model | COMBO | mattmdjaga/segformer_b2_clothes | 4 options: mattmdjaga/segformer_b2_clothes, sayeed99/segformer_b3_clothes, sayeed99/segformer-b2-fashion, sayeed99/segformer-b3-fashion |
| batch_size | INT | 51–50 | — |
| max_megapixels | FLOAT | 2.01–999 | — |
| detail_erode | INT | 121–255 | — |
| detail_dilate | INT | 61–255 | — |
| process_detail | BOOLEAN | true | — |
| detail_method | COMBO | VITMatte_fast | 4 options: VITMatte_fast, VITMatte, GuidedFilter, PyMatting |
| expand_mask | INT | 0-255–255 | — |
| tapered_corners | BOOLEAN | true | — |
| black_point | FLOAT | 0.150.01–0.98 | — |
| white_point | FLOAT | 0.990.02–0.99 | — |
| device | COMBO | cpu | 1 options: cpu |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| mask | MASK | — |