LayerMask: Segformer Ultra V3
Segformer Ultra V3 — auto-mask clothes, faces and body parts by name
- image
- segformer_model
- segformer_setting
- image
- mask
Say you want to mask just the shirt so you can recolor it, or just the hair, or just the face - not "the whole person," but a specific named part. That's semantic segmentation, and it's a different job from background removal. BiRefNet or SAM will happily cut the subject out of the scene; they won't hand you "upper garment" as its own mask. Segformer will. This node runs a Segformer parsing model over your image, keeps the classes you asked for, and - this is the "Ultra" part - refines the edges of that mask so it's actually clean enough to composite or inpaint through.
Think of it as two tools welded together: a clothes/face/body parser to find the region, and the same edge-matting step from MaskEdgeUltraDetail to sharpen it. One node, semantic mask out.
How it works
Segformer is a segmentation transformer trained on parsing datasets - clothing sets, face-parsing sets, human-parsing sets. It labels every pixel with a class. You pick a model and tell it which classes to keep; everything else becomes background. Then, if process_detail is on, it runs your chosen matting method over the mask edge (the trimap-band trick) so hair and fabric fringes come out as soft alpha instead of a stair-stepped line.
The inputs and outputs that matter
segformer_modelandsegformer_setting- these two aren't things you type. They're special inputs (typesLS_SEGFORMER_MODELandLS_SEGFORMER_SETTING) that come from the pack's own Segformer loader and setting nodes. The loader picks which parsing model; the setting node is where you tick the classes you want (e.g. "upper clothes," "hair," "face"). Wire those two in or this node has nothing to work with.detail_method- the edge refiner:VITMatte(best, downloads a model), orPyMatting/GuidedFilter(no download).process_detail- turn the edge refinement off to go faster when you only need a rough mask.detail_erode/detail_dilate,black_point/white_point- the same trimap-band and alpha-levels controls as the other Ultra nodes.max_megapixels- VRAM/speed throttle for the matting step.
Out come an image and a mask. The mask is the thing you're usually after - feed it into an inpaint, a color adjustment, or a composite.
How to install it
It ships in the LayerStyle pack. Via ComfyUI Manager: search LayerStyle, install, restart. Manually:
cd ComfyUI/custom_nodes
git clone https://github.com/chflame163/ComfyUI_LayerStyle
pip install -r ComfyUI_LayerStyle/requirements.txt
then restart. Find it under 😺dzNodes → LayerMask, alongside its companion Segformer loader and setting nodes.
Common issues & troubleshooting
Two separate model downloads on first run. The Segformer parsing weights download the first time the loader runs, and if you use the VITMatte detail method, that model downloads too (from hustvl/vitmatte-…-composition-1k). Both come from HuggingFace, and both will hang forever if your network blocks HF - the classic symptom is the console stuck on "Downloading …". Let them complete once on a good connection, or switch the detail method to PyMatting/GuidedFilter to skip that half.
The pack won't import at all. LayerStyle leans on a big transformers install, and the most common failure people hit is transformers itself being broken (frequently a stray TensorFlow in the venv), which takes the whole pack down - every LayerStyle node vanishes at once. Check the startup traceback for the named library, use Manager's "Try Fix," or repair that one dependency.
The mask grabs the wrong thing. That's the segformer_setting node, not this one - you've kept the wrong classes. Different parsing models expose different class lists, so match the model to what you're masking (a clothes model won't have a "sky" class).
Edges still rough. Make sure process_detail is on, then widen detail_erode/detail_dilate a little so the matting has more edge to solve.
Inputs (10)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| segformer_model | LS_SEGFORMER_MODEL | — | |
| segformer_setting | LS_SEGFORMER_SETTING | — | |
| detail_method | COMBO | 5 options: VITMatte, VITMatte(local), vitmatte-base-composition-1k, PyMatting, GuidedFilter | |
| detail_erode | INT | 81–255 | — |
| detail_dilate | INT | 61–255 | — |
| black_point | FLOAT | 0.010.01–0.98 | — |
| white_point | FLOAT | 0.990.02–0.99 | — |
| process_detail | BOOLEAN | true | — |
| max_megapixels | FLOAT | 2.01–999 | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| mask | MASK | — |