Nodes/ComfyUI Layer Style/LayerMask: Segformer Ultra V2
ComfyUI Node Runs on cloud

LayerMask: Segformer Ultra V2

Segformer Ultra V2

By chflame163·Created 3 years ago·Updated 4 days ago· 3,113
LayerMask: Segformer Ultra V2
  • image
  • segformer_pipeline
  • image
  • mask
◄detail_method▾►
â—„detail_erode8â–º
â—„detail_dilate6â–º
â—„black_point0.01â–º
â—„white_point0.99â–º
â—„process_detailtrueâ–º
◄device▾►
â—„max_megapixels2.0â–º

This is the node that turns a Segformer segmentation into a mask you can actually composite with. On its own, Segformer labels every pixel into categories - this is a person's shirt, that's hair, that's background - but the raw output has blocky, aliased edges that look terrible the moment you paste the subject onto a new background. SegformerUltraV2 takes that coarse label map and refines the edges into a clean, feathered alpha. It's the second half of a two-node combo, and it's where the quality actually comes from.

The pairing is the whole idea. You feed it a segformer_pipeline from a loader node - the Fashion Pipeline loader in this same pack is the usual source - plus the original image, and it runs the segmentation and then the edge refinement in one shot. The pipeline is what decides what gets masked; this node decides how good the mask boundary is.

That refinement is the part worth understanding, because the detail_method dropdown is doing real work. Segmentation gives you a hard foreground/background label per pixel, which is structurally wrong for hair strands, fabric mesh, or any soft edge - that's a job for matting, which predicts fractional alpha instead of a yes/no label. So this node runs a matting pass over the segmentation boundary. VITMatte is the high-quality option (a transformer matting model, downloads on first use); VITMatte(local) uses a locally cached copy so it won't hit HuggingFace mid-run; PyMatting and GuidedFilter are lighter CPU-side methods that are faster but softer. If VITMatte is choking your VRAM or you just want speed, GuidedFilter is a reasonable fallback. If edge quality is the whole point, VITMatte.

The handful of settings you'll actually touch: detail_erode and detail_dilate control how far the refinement reaches inward and outward from the segmentation edge - think of it as the width of the band where matting is allowed to redraw the boundary. black_point and white_point are levels on the resulting alpha; nudge white_point down if the mask isn't reaching full opacity in the middle, nudge black_point up if the background isn't going fully transparent. process_detail is the master switch - turn it off and you get the raw segmentation with none of the refinement, which is faster and occasionally all you need. max_megapixels caps the resolution the matting runs at, which is your main lever if you're running out of memory on big images. device lets you push it to CPU if CUDA is tight.

Two outputs: image (the subject on transparency) and mask (the refined alpha). The mask is the one you care about - wire it into a composite, an inpaint, or a detailer.

Install is the pack standard. In ComfyUI Manager, search "ComfyUI Layer Style" and install, or from a terminal cd ComfyUI/custom_nodes && git clone https://github.com/chflame163/ComfyUI_LayerStyle, then pip install -r requirements.txt and restart. Heads up specific to the Segformer nodes: in current versions of the pack the author split the heavier AI nodes out into a companion repo, ComfyUI_LayerStyle_Advance - if the Segformer nodes don't show up after installing the base pack, that's where they moved, so install that one too. The VITMatte weights and the Segformer models download to ComfyUI/models/ on first run, so the first execution pauses while they pull.

Where people get burned: the LayerStyle pack is notorious for "failed to import" errors, almost always a Python dependency clash - usually transformers or timm versions fighting with something else in your environment. There's an actual r/comfyui thread offering fifty bucks to whoever fixes it. If the node loads red, don't fiddle with the workflow - hit "Try Fix" in Manager, and if that fails, reinstall the pack's requirements.txt into your venv and check your transformers version. The other gotcha is forgetting the pipeline loader entirely: this node does nothing without a segformer_pipeline feeding its input.

Category😺dzNodes/LayerMask

Inputs (10)

NameTypeDefaultDescription
imageIMAGE—
segformer_pipelineSegPipeline—
detail_methodCOMBO5 options: VITMatte, VITMatte(local), vitmatte-base-composition-1k, PyMatting, GuidedFilter
detail_erodeINT81–255—
detail_dilateINT61–255—
black_pointFLOAT0.010.01–0.98—
white_pointFLOAT0.990.02–0.99—
process_detailBOOLEANtrue—
deviceCOMBO2 options: cuda, cpu
max_megapixelsFLOAT2.01–999—

Outputs (2)

NameTypeDescription
imageIMAGE—
maskMASK—