Ghostwritten BiRefNet Loader
This Node Doesn't Do the Cutout — Here's What It's Actually For
- birefnet_model
Ghostwritten BiRefNet Loader is the boring half of the two-node
Ghostwritten Studios BiRefNet pack, and boring is the job. It doesn't remove
anything. It loads a BiRefNet segmentation model once, hands you a
BIREFNET_MODEL handle, and lets you share that handle across as many
Remove Background nodes as you like. The actual cutout happens in
Ghostwritten Remove Background; this is the optional loader in front of it.
So why does the loader exist at all? Mostly organization. The Remove Background node is perfectly happy to lazy-load a model itself - if you never touch this node, the workflow still runs. The loader buys you a single knob for model and precision when you've got several remove nodes in one graph, say because you're comparing the general weights against the portrait or HR variants on the same image. Switch once at the top instead of hunting through every downstream node. That's a small win, but when you're iterating on a cutout workflow it's the kind of small win you stop noticing only after you've got it.
How it works
Under the hood it's a thin wrapper. The node maps your friendly model name to a
Hugging Face repo ID from a hardcoded registry (ZhengPeng7/BiRefNet,
BiRefNet_lite, BiRefNet-portrait, BiRefNet_HR), picks a device - CUDA,
then MPS, then CPU - and loads the weights through
transformers.AutoModelForImageSegmentation with trust_remote_code=True.
Loaded models go into a global cache keyed on (repo, device, dtype), so
repeated runs reuse the weights instead of re-reading them off disk. The output
handle is just that loaded model plus its device, dtype, and input size.
Two things follow from that. First, the weights are pulled straight from Hugging
Face on first use and cached under ~/.cache/huggingface - this pack does not
read ComfyUI's models/background_removal/ folder, so even if you already have
the BiRefNet safetensors that ComfyUI core ships, the first run still downloads
its own copy. Second, precision only does anything on CUDA. The source
falls back to fp32 on MPS and CPU, silently. fp16 is the default and the right
call on a GPU - it costs essentially no accuracy - but don't pick fp32 on a Mac
and expect it to matter, because you were getting fp32 anyway.
The inputs that matter
- model_name -
BiRefNet (general)(the default, best all-rounder),BiRefNet_lite (faster)(Swin-Tiny, less accurate, lighter),BiRefNet-portrait(people, trained on P3M-10k), orBiRefNet HR (1536)(for bigger inputs, at a VRAM cost). - precision -
fp16default,fp32if you must. On CUDA, fp16 is the one to use.
One honest caveat about that HR entry: the pack runs it at 1536px internally, even though the HR weights were trained at 2048. Feed it a 4K render and it will still downscale - fine for most sources, but if your whole reason for reaching for HR is very large inputs, you're leaving some of it on the table.
Install and gotchas
Install is the same for the whole pack, so once it's in you get the Remove Background node free. Easiest is ComfyUI Manager: search "comfyui-ghostwritten-BiRefNet" (or just "Ghostwritten") and install. Otherwise:
cd ComfyUI/custom_nodes
git clone https://github.com/GhostwrittenStudios/comfyui-ghostwritten-BiRefNet
Restart ComfyUI so the nodes register. The pack needs timm, einops, and
kornia on top of the transformers and torch that already ship with
ComfyUI - Manager usually handles those, but if the loader throws an import
error, that's what's missing. The first load will look like it's hung: it's
downloading a few hundred MB of weights over the network. Let it finish once and
it's cached forever. If you wired a loader into your graph and a Remove
Background node still re-loads, check that the loader's birefnet_model output
is actually connected to that node's input - that's the whole deal here.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| model_name | COMBO | 4 options: BiRefNet (general), BiRefNet_lite (faster), BiRefNet-portrait, BiRefNet HR (1536) | |
| precision | COMBO | fp16 | 2 options: fp16, fp32 |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| birefnet_model | BIREFNET_MODEL | — |