Nodes/ComfyUI-BiRefNet-TRT/🔥BiRefNet RMBG
ComfyUI Node

🔥BiRefNet RMBG

The background-removal node that finally keeps the hair

By jesenzhang·Created 2 years ago·Updated 2 years ago· 0
🔥BiRefNet RMBG
  • birefnet
  • image
  • image
  • mask
â—„background_color_nametransparencyâ–º

BiRefNet is the model that quietly displaced rembg's u2net for anything with a difficult edge - flyaway hair, fur, fabric mesh, glass. BiRefNet_RMBG is the matting half of a two-node pack: feed it an image and an already-loaded BiRefNet model, and it hands back a cutout with real alpha (or flattened onto a solid color) plus the raw mask. The name is honest about the job: RMBG, remove background.

The "TRT" in the pack title is the other half of the pitch. jesenzhang's fork exists so you can run BiRefNet through TensorRT engines and skip a big chunk of inference time. But here's the thing - if you never build a TRT engine, this is still a perfectly good PyTorch BiRefNet wrapper. You're just leaving the headline feature on the table.

One honest caveat before you commit: recent ComfyUI ships BiRefNet natively (since May 2026, in models/background_removal/), so a core node covers the plain-cutout case. This pack earns its slot when you want the explicit mask output, the TRT speed path, or you're on a build older than that.

How it works

The node never touches the model file directly. The birefnet socket takes the output of the pack's other node, BiRefNet_ModelLoader ("🔥BiRefNet Loader"), which decides whether you're running PyTorch weights, an ONNX export, or a .engine / .trt / .plan TensorRT engine and passes a small descriptor down the wire. The wiring is always Loader → RMBG → output.

Under the hood the RMBG node does the standard BiRefNet dance: resize to 1024×1024 (bilinear), normalize with ImageNet stats, run the network, sigmoid the logit into an alpha map, interpolate back to your original dimensions, and stretch to full contrast with min-max normalization. Then it pastes your original image onto whatever background you picked, using the mask as the paste channel.

That internal 1024×1024 resize is the detail to remember. Feed a 4K image and the model is still seeing 1024×1024 - the mask gets upscaled back, but the fine edge detail you wanted at full resolution was never computed. For big inputs you want the HR or dynamic-resolution BiRefNet weights, not the standard 1024 checkpoint.

The inputs and outputs that matter

Only three inputs, and you'll touch two of them:

  • birefnet - the loader output. No choice involved.
  • image - the image to cut out.
  • background_color_name - defaults to transparency, which returns an RGBA image with real alpha. Pick any of the 26 named colors (green, white, red…) and you get an RGB cutout composited onto that solid background instead. The green-screen option is handy if a downstream pipeline expects a chroma key.

Outputs are image (the composited cutout) and mask (the grayscale alpha map). Wire the mask into anything that wants a soft selection - a compositing node, a blur, a color grade that should only hit the subject.

Install

Via ComfyUI Manager, search "ComfyUI-BiRefNet-TRT", or the manual route:

cd ComfyUI/custom_nodes
git clone https://github.com/jesenzhang/ComfyUI-BiRefNet-TRT
cd ComfyUI-BiRefNet-TRT
pip install -r requirements.txt

Then restart ComfyUI. Models live in ComfyUI/models/BiRefNet/. The loader's load_mode defaults to local (pick a .pth from that folder) or pretrained, which pulls weights straight from HuggingFace's ZhengPeng7/BiRefNet.

Where people get burned

  • The requirements.txt is optimistic. It lists tensorrt, cuda and ctypes as pip packages. ctypes is a standard-library module, cuda is a meta-package that does nothing, and real TensorRT on Windows is not a simple pip install - it comes from NVIDIA's installer. If you're only on the PyTorch path, let timm, kornia and friends install and skip the TRT ones. You do not need TensorRT to cut out a background.
  • The README lists pythongosssss/ComfyUI-Custom-Scripts as a requirement. The loader uses its pysssss.binding trick to swap the model dropdown between local and pretrained lists, so without it the UI behaves oddly. It's a one-click install through Manager.
  • No loader, no output. The birefnet socket is required - there's no load-here shortcut on this node. Missing BRNMODEL inputs are the classic way beginners stall.
  • If you do build a TRT engine, it must be built at 1024×1024 input - the node hardcodes that shape on the TensorRT path. Convert with ComfyUI_TensorRT and drop the .engine into the same models/BiRefNet folder.

Honestly, the plain PyTorch path at 1024 is already sub-second on a 4090. Reach for TensorRT when you're processing batches and the mask generation is your bottleneck - not when you're cutting out one hero image.

Category🧹BiRefNet

Inputs (3)

NameTypeDefaultDescription
birefnetBRNMODEL—
imageIMAGE—
background_color_nameCOMBOtransparency26 options: transparency, green, white, red, yellow, blue, +20

Outputs (2)

NameTypeDescription
imageIMAGE—
maskMASK—