Remove Background (Afnm)
One node, one model, background gone — the RMBG cutout that skips the dependency circus
- image
- image
- mask
Remove Background (Afnm) is the whole pack: one node, one job, one model. Feed it an image, and you get the subject cut out with a transparent background plus the mask it used. That's it. If you've ever installed one of the big background-removal suites and spent an hour chasing missing dependencies, this is the opposite experience.
The pack is a one-commit effort from Philip Liddell (GitHub: Lyeeedar), and the project metadata says it exists for "Afnm game asset generation" - an internal asset pipeline that got published. That's why you've never heard of it. Zero impressions, no community chatter, no drama. It's the kind of personal workflow node the ecosystem quietly runs on, and it happens to be genuinely well-built for what it does.
What it actually is
Under the hood it's RMBG-2.0, 1038lab's re-implementation of BiRefNet - the bilateral-reference segmentation network that became this space's default cutout model. The bilateral reference (source image patches plus gradient maps) is the trick that keeps hair and fur edges alive where older u2net-based cutouts turned them to mush.
One honest take before you commit: RMBG-2.0 is not the quality ceiling. The occasional reddit commenter calls plain BiRefNet or BEN ahead of it on the genuinely nasty cases, and the knowledge base's own read is that nobody has "won" background removal anyway. What this node wins at is convenience - one model, auto-downloaded, no model selection UI to trip over.
The inputs that matter
The only required input is image. Everything else has a sensible default, and these are the ones you'll actually touch:
process_res(default 1024) - the resolution the image is resized to before inference. 1024 is BiRefNet's native training size, and this is where people shoot themselves: cutting out a 2K asset at default 1024 silently downscales and throws away exactly the edge detail you wanted. Bump it toward 2048 (the max) for big inputs.sensitivity(default 1.0, range 0–1) - the naming is a trap. The code multiplies the raw mask by2 - sensitivity, so lower is more aggressive. Drop it to 0.85 if edges are under-shooting.mask_offset(-64..64) - positive grows the mask, negative shrinks it. A little positive (+2 or so) fights the white halo on hair.mask_blur(0–64) - pixel-radius Gaussian feather on the mask. 0 is a razor edge; a couple of pixels hides jaggies.refine_foreground- a hand-rolled defringe that softens the semi-transparent edge band. Cheap, and usually worth leaving on.invert_output- flips which side survives, for when the model calls the background the subject.
Outputs are image (the RGBA cutout) and mask (the raw mask, handy for wiring into anything else). One ComfyUI caveat: not every downstream node preserves alpha. If your saved PNG comes back with a black background, save through a node that respects the alpha channel rather than blaming the cutout.
Installing it
ComfyUI Manager → search comfyui-afnm-rmbg, or:
cd ComfyUI/custom_nodes
git clone https://github.com/Lyeeedar/comfyui-afnm-rmbg
Restart ComfyUI. First run downloads four files from 1038lab/RMBG-2.0 on HuggingFace - the weights are a chunky ~885 MB - into ComfyUI/models/RMBG/RMBG-2.0/, automatically. No manual model hunting. The pack's own dependency list is minimal (huggingface_hub, safetensors, torchvision), though the code also imports transformers and OpenCV at runtime - both of which ComfyUI itself already ships. If first run dies with an ImportError on transformers, that's what's happening; pip install transformers fixes it.
Troubleshooting
- First run shows "Downloading 4 file(s)…" and sits there - that's the 885 MB. Let it finish once.
- Halo / white fringe on hair - lower
sensitivitya touch, addmask_offset+2, and/or enablerefine_foreground. - Wrong region removed -
invert_output = true. - VRAM - this loader keeps FP32 weights (no half-precision conversion), so budget roughly 4–5 GB at 1024, in line with BiRefNet's own FP32 numbers. Keep
process_resat 1024 if you're tight.
One last pointer: ComfyUI shipped native BiRefNet into models/background_removal/ in May 2026. If you already run that, this pack is a convenience alternative, not a quality upgrade - but for a zero-dependency single-node cutout in the middle of an asset pipeline, it's hard to beat.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| sensitivityopt | FLOAT | 1.000–1 | — |
| process_resopt | INT | 1024256–2048 | — |
| mask_bluropt | INT | 00–64 | — |
| mask_offsetopt | INT | 0-64–64 | — |
| invert_outputopt | BOOLEAN | false | — |
| refine_foregroundopt | BOOLEAN | false | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| mask | MASK | — |