LayerMask: BiRefNetUltra(Advance)
BiRefNetUltra — ComfyUI Node Guide
- image
- image
- mask
This is the pack's all-in-one BiRefNet cutout node - no separate model-loader step, just wire in an image and get a mask back. BiRefNet earned its reputation for exactly one reason: it's noticeably better than the old rembg/u2net default on the cases that actually matter, hair, fur, fabric mesh, the fine boundaries that a plain segmentation model just smears over. It's MIT-licensed with no commercial-use catch, and it's genuinely become the community default for anything with a difficult edge - though it's worth knowing InSPyReNet still wins some head-to-head comparisons people run, so if BiRefNet isn't nailing a particular image, that's a real alternative worth trying rather than assuming your settings are wrong.
The mechanism is a two-module design: one part places the object using broad scene understanding, the other reconstructs the mask using both the image's own detail and a gradient map as a second reference, which is the specific trick that lets hair strands survive instead of blurring into a blob. This node doesn't expose a model-file picker - unlike the pack's LoadBiRefNetModel/BiRefNetUltraV2 pairing, it manages its own checkpoint internally, so there's one less thing to configure.
Inputs that actually matter:
image- your source.detail_method- five choices:VITMatte,VITMatte(local),vitmatte-base-composition-1k,PyMatting,GuidedFilter. VITMatte gives the sharpest edges but costs more;VITMatte(local)uses a model you've already downloaded once rather than re-fetching; PyMatting and GuidedFilter are lighter, faster fallbacks if you don't need pixel-perfect hair strands.max_megapixels(default 2) - caps the resolution the detail pass runs at. This matters more than people expect: feeding a 4K image straight through without raising this can throw away exactly the fine edges you were trying to preserve, since the model downscales internally past this cap.
The rest of the edge-refinement knobs - detail_erode, detail_dilate (both default around 6, controlling how far the refinement reaches inward/outward from the detected edge), black_point/white_point (edge sampling thresholds), and process_detail (the master on/off for the whole refinement pass) - follow the same pattern as every other "Ultra" node in this pack. Turn process_detail off if you just need a fast rough mask and don't care about hair-level precision. device picks cuda or cpu.
Outputs are image (pass-through) and mask, ready for compositing or feeding into a crop/inpaint step.
Installing it: ComfyUI Manager, search "ComfyUI Layer Style Advance," or git clone https://github.com/chflame163/ComfyUI_LayerStyle_Advance into custom_nodes, then install_requirements.bat (or Aki variant) / pip install -r requirements.txt, then repair_dependency.bat, restart. Model files (BiRefNet-ep480.pth, pvt_v2_b2.pth, pvt_v2_b5.pth, and the two swin backbone files) come from huggingface.co/ViperYX/BiRefNet or BaiduNetdisk, into ComfyUI/models/BiRefNet. Nodes named "Ultra" across this whole pack - this one included - also need the VITMatte model if you're using that detail method: hustvl/vitmatte-small-composition-1k into ComfyUI/models/vitmatte.
Where people get stuck: if edges look worse on a high-res input than they did on a test image, check max_megapixels first - that's the classic self-inflicted quality loss with this model family, not a bad checkpoint. And if the node throws a VitMatteImageProcessor import error, that's an outdated transformers package, fixable with repair_dependency.bat or a manual transformers upgrade - a known, documented issue for this specific dependency in the README.
Inputs (9)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| detail_method | COMBO | 5 options: VITMatte, VITMatte(local), vitmatte-base-composition-1k, PyMatting, GuidedFilter | |
| detail_erode | INT | 61–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 | — |
| device | COMBO | 2 options: cuda, cpu | |
| max_megapixels | FLOAT | 2.01–999 | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| mask | MASK | — |