LayerMask: Segformer B2 Clothes Ultra
SegformerB2ClothesUltra — mask clothes and body parts with clean edges
- image
- image
- mask
If you want to grab just the dress, or just the upper body, or everything except the hair - this is the node for it. SegformerB2ClothesUltra runs a clothing-and-body-part segmentation model, lets you tick exactly which parts you want, and then cleans the mask edges with a matting pass so it survives hair and fabric instead of coming out blocky. It's the go-to in the Layer Style pack for virtual try-on, garment inpainting, and any "select the clothes" job.
How it works
Under the hood it's SegFormer B2 fine-tuned on a clothes-parsing dataset - the mattmdjaga/segformer_b2_clothes model. SegFormer labels every pixel with a category (face, hair, upper clothes, skirt, pants, and so on), and this node lets you union together whichever labels you check into a single mask.
The Ultra part is what makes it worth using over a bare segmentation node. Raw semantic masks are hard-edged - each pixel is either in or out - which looks fine on a solid sleeve and terrible on a fuzzy collar or a wisp of hair. The knowledge base makes the distinction plainly: a segmentation model labels pixels foreground/background, which is structurally wrong for anything with a soft edge, so you want a matting refinement on top. That's exactly what the detail_method does here, running the mask boundary through a matting algorithm to recover fractional alpha along the tricky edges.
The inputs that matter
- The part toggles -
face,hair,hat,sunglass,left_arm,right_arm,left_leg,right_leg,upper_clothes,skirt,pants,dress,belt,shoe,bag,scarf. All off by default; tick the ones you want combined into the mask. detail_method- the edge refiner:VITMatte(the quality pick, downloads a matting model),VITMatte(local),vitmatte-base-composition-1k,PyMatting, orGuidedFilter(lighter, no model). Start with VITMatte for hair, drop to GuidedFilter if you're low on VRAM.detail_erode/detail_dilate- how far in/out from the mask edge the refinement reaches. Bump these if the boundary is being cut too tight or too loose.black_point/white_point- the mask's contrast; tighten these if the mask is leaking gray where it should be solid.process_detail- turn the refinement off entirely for a fast, hard-edged preview.
Outputs are image (the input with the mask applied) and mask - feed the mask into an inpaint, a composite, or ImageBlendAdvance from the same pack.
How to install it
ComfyUI Manager: search ComfyUI Layer Style, install, restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/chflame163/ComfyUI_LayerStyle
install requirements.txt, restart. The node is under 😺dzNodes → LayerMask.
Common issues and troubleshooting
The number-one problem with the Segformer nodes, and it's all over the forums, is the model not being present. If the node errors on load or at runtime with something like "Can't load image processor… make sure the path contains a preprocessor_config.json", the segformer_b2_clothes model didn't download. The fix people confirm working is to fetch it by hand into the pack's model folder - clone https://huggingface.co/mattmdjaga/segformer_b2_clothes into the checkpoints directory and restart. First-run auto-download also fails behind a proxy or a flaky HF connection, so the manual clone is the reliable path either way.
The other footgun is detail_method: VITMatte pulls a second model (the vitmatte-base-composition-1k matting weights) the first time you use it, so if that's what's erroring, it's the same missing-model story one layer down. If you don't need model downloads at all, GuidedFilter refines the edge with no weights - lower quality on hair, but it always runs. And if you're masking the same subject repeatedly, pair the SegformerClothesPipelineLoader with an apply node so the model loads once instead of per-execution.
Inputs (25)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| face | BOOLEAN | false | — |
| hair | BOOLEAN | false | — |
| hat | BOOLEAN | false | — |
| sunglass | BOOLEAN | false | — |
| left_arm | BOOLEAN | false | — |
| right_arm | BOOLEAN | false | — |
| left_leg | BOOLEAN | false | — |
| right_leg | BOOLEAN | false | — |
| upper_clothes | BOOLEAN | false | — |
| skirt | BOOLEAN | false | — |
| pants | BOOLEAN | false | — |
| dress | BOOLEAN | false | — |
| belt | BOOLEAN | false | — |
| shoe | BOOLEAN | false | — |
| bag | BOOLEAN | false | — |
| scarf | BOOLEAN | false | — |
| detail_method | COMBO | 5 options: VITMatte, VITMatte(local), vitmatte-base-composition-1k, PyMatting, GuidedFilter | |
| detail_erode | INT | 121–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 | — |
| device | COMBO | 2 options: cuda, cpu | |
| max_megapixels | FLOAT | 2.01–999 | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| mask | MASK | — |