Nodes/ComfyUI_LayerStyle_Advance/LayerMask: BiRefNet Ultra V2(Advance)
ComfyUI Node Runs on cloud

LayerMask: BiRefNet Ultra V2(Advance)

BiRefNet Ultra V2 — the default background-removal model, wrapped with proper edge detail

By chflame163·Created 2 years ago·Updated 4 months ago· 696
LayerMask: BiRefNet Ultra V2(Advance)
  • image
  • birefnet_model
  • image
  • mask
detail_method
detail_erode4
detail_dilate2
black_point0.01
white_point0.99
process_detailfalse
device
max_megapixels2.0

If you only remember one background-removal model name, it should be BiRefNet. It's the thing that made rembg's old default (u2net) look dated, specifically on the cases that always broke segmentation models - hair, fur, semi-transparent fabric. This node is chflame163's wrapper around it, and V2 is the version to use: it takes the BiRefNet model as an external input rather than baking a specific checkpoint in, which means you load the model once with a separate loader node and can swap weights without rebuilding your whole graph.

Worth knowing before you reach for it: BiRefNet wasn't actually built for background removal. The underlying paper targets "dichotomous image segmentation," and the same weights happen to top salient-object and camouflaged-object benchmarks too - background removal is just the application that ran away with the model's reputation, because the edge quality is visibly better than anything that came before it on real photos. It's MIT-licensed with no acceptable-use restrictions, so it's fine for commercial work.

This node itself is intentionally thin - the model loading happens in the separate Load BiRefNet Model V2 node, which you wire into the birefnet_model input here. What you actually tune is the edge-refinement pipeline that runs after segmentation: detail_method picks the technique (VITMatte gives the sharpest hair edges but costs the most memory on large images; PyMatting and GuidedFilter are lighter), detail_erode and detail_dilate nudge the mask boundary inward or outward, black_point/white_point are the sampling thresholds that control how aggressively the edge cleanup treats near-black and near-white pixels, and max_megapixels caps the resolution VITMatte processes at full quality. One thing worth noticing: process_detail defaults to false here, unlike most of the pack's other masking nodes where it defaults to true - the README explains why, straightforwardly: BiRefNet's own edge output is already good enough that the extra refinement pass often isn't necessary. Turn it on if you're still seeing rough edges on tricky material, but don't assume you need it by default. Outputs are image and mask.

Install the pack via ComfyUI Manager (search "ComfyUI Layer Style Advance") or git clone https://github.com/chflame163/ComfyUI_LayerStyle_Advance into custom_nodes/, restart, and run the requirements installer. For the model itself, BiRefNet V2 support specifically wants BiRefNet-general-epoch_244.pth in ComfyUI/Models/BiRefNet/pth (note the capital "Models" in that path per the README - it matters on case-sensitive filesystems), downloadable from the author's Baidu/Google Drive links or bundled in the full HuggingFace model repo. You can drop additional BiRefNet checkpoints in the same folder and pick between them from the loader node. If you're doing edge refinement with VITMatte, grab that model separately into ComfyUI/models/vitmatte.

Troubleshooting here overlaps with the rest of the pack's matting-heavy nodes: a cv2.ximgproc guidedFilter error is a bad opencv-contrib-python install (run repair_dependency.bat), a VitMatteImageProcessor import failure means your transformers package needs updating, and if you get a ValueError: Trimap did not contain foreground values when process_detail is on, that's PyMatting choking because the masked area is too large or too small relative to the image - either adjust your erode/dilate settings or switch detail methods for that image. If you're chasing genuinely the sharpest possible cutout on hair and fur, it's worth knowing the honest caveat from real-world testing: even BiRefNet's best results on tricky portraits usually still need some manual touch-up - nothing in this space is fully solved yet.

Category😺dzNodes/LayerMask

Inputs (10)

NameTypeDefaultDescription
imageIMAGE
birefnet_modelBIREFNET_MODEL
detail_methodCOMBO5 options: VITMatte, VITMatte(local), vitmatte-base-composition-1k, PyMatting, GuidedFilter
detail_erodeINT41–255
detail_dilateINT21–255
black_pointFLOAT0.010.01–0.98
white_pointFLOAT0.990.02–0.99
process_detailBOOLEANfalse
deviceCOMBO2 options: cuda, cpu
max_megapixelsFLOAT2.01–999

Outputs (2)

NameTypeDescription
imageIMAGE
maskMASK