Nodes/ComfyUI-Segformer_Ultra_Fast/Segformer B2 Clothes Ultra-Fast
ComfyUI Node

Segformer B2 Clothes Ultra-Fast

The fastest way to mask clothes (or a whole person) in ComfyUI

By lihaoyun6·Created 11 months ago·Updated 11 months ago· 39
Segformer B2 Clothes Ultra-Fast
  • image
  • labels
  • image
  • mask
modelmattmdjaga/segformer_b2_clothes
batch_size5
max_megapixels2.0
detail_erode12
detail_dilate6
process_detailtrue
detail_methodVITMatte_fast
expand_mask0
tapered_cornerstrue
black_point0.15
white_point0.99
devicecpu

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; bump device to your GPU for video.
  • labels - a wildcard * input. Feed it from a matching Label node: Segformer Clothes Label for the b2/b3-clothes models, Segformer Fashion Label for 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 to mattmdjaga/segformer_b2_clothes. The b3 variants are a touch more accurate and slower; the fashion variants are for fine garment details.
  • process_detail and detail_method - edge refinement. VITMatte_fast (the default) runs a second, small matting model on a trimap to get soft hair and fabric edges; VITMatte is the same but slower and marginally better; GuidedFilter skips the extra model entirely; PyMatting uses the pymatting library, which is not in the pack's requirements - pick it and you'll likely crash until you pip 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.
  • PyMatting crash - needs pymatting installed 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.

CategorySegformer Ultra-Fast/Mask

Inputs (14)

NameTypeDefaultDescription
imageIMAGE
labels*
modelCOMBOmattmdjaga/segformer_b2_clothes4 options: mattmdjaga/segformer_b2_clothes, sayeed99/segformer_b3_clothes, sayeed99/segformer-b2-fashion, sayeed99/segformer-b3-fashion
batch_sizeINT51–50
max_megapixelsFLOAT2.01–999
detail_erodeINT121–255
detail_dilateINT61–255
process_detailBOOLEANtrue
detail_methodCOMBOVITMatte_fast4 options: VITMatte_fast, VITMatte, GuidedFilter, PyMatting
expand_maskINT0-255–255
tapered_cornersBOOLEANtrue
black_pointFLOAT0.150.01–0.98
white_pointFLOAT0.990.02–0.99
deviceCOMBOcpu1 options: cpu

Outputs (2)

NameTypeDescription
imageIMAGE
maskMASK