FeyNobg 抠图 / FeyNobg Matting
One-click background removal that doesn't need a prompt
- image
- alpha
- cutout
If you've used ComfyUI for any amount of time, you know the background-removal drill: BiRefNet is the default, hair survives, and the best results come from a model that was never built for the job. FeyNobg 抠图 / FeyNobg Matting is that lineage pushed one step further - a node wrapping feyn's open FeyNobg model (Apache-2.0), which takes BiRefNet and adds gradient attention, image-patch injection, and multi-scale input on a Swin-Large backbone. No prompt, no click on the subject, no trimap. Drop an image in, get an alpha out.
The 1.05GB weights auto-download to ComfyUI/models/nobg/FeyNobg on first run, so install is effectively zero-work if you have the pack.
What it's for, and what it isn't
FeyNobg is the "find the main subject and strip the background clean" node. Fast, one step, ideal for batch-processing photos or character renders where the subject is obvious. Its sibling in the same pack - Lucida - is the one that deliberately keeps glass, text, and semi-transparent stuff. They're complementary, not competing: the README's comparison shows FeyNobg isolating a character while Lucida keeps the clouds as foreground. Decide by what your material needs.
Inputs that matter
- image - batches fine; it processes per-frame to keep the VRAM peak down. RGBA input silently drops the alpha and uses RGB.
- resolution - default 1024, the model's native training size. Lower saves VRAM but coarsens edges; higher doesn't necessarily help and can break structure.
- precision -
fp32is the default, but the README measuredfp16output as identical (same alpha mean, 0.657) at half the VRAM and visibly faster. On a 12GB card, use fp16. - device -
auto/cpu. CPU is ten-plus times slower; only for genuinely out-of-VRAM situations.
Optional: alpha_threshold (0.5), alpha_softness (1.0 = no-op), keep_aspect_ratio, invert_mask.
Outputs: alpha (MASK) and cutout (IMAGE on a black background). For a transparent PNG, wire alpha into a JoinImageWithAlpha-style node.
The "whole subject went translucent grey" rescue
The model outputs ~0.5 mid-values for areas it's unsure about, which shows up as the subject looking faint and see-through. The model itself has no inference-time dial for this, so the node gives you a post-process level adjustment. Set alpha_threshold to 0.35 and alpha_softness to 0.3 - the README measured that cutting the translucent-pixel share from 1.49% to 0.31% while barely moving the subject mean. Two honest caveats from the author: it only rescues regions the model already half-recognized (alpha near zero stays near zero), and smaller softness eats real semi-transparent detail like hair. Set softness to 0 for a hard binary edge - fine for solid subjects, bad for hair or glass.
Where people get burned
The near-black-alpha failure is the scary one: the pack's FeyNobg weights were exported under transformers 5.x with renamed Swin backbone keys, and a naive load maps only 405 of 958 parameters - the model runs, doesn't error, and outputs almost nothing. This node renames the keys to match your environment and validates strictly, aborting on any mismatch rather than silently degrading. The takeaway is that you should never see all-black alpha here; if you do, it's a transformers-version mismatch, and switching the environment rather than the node is the fix.
For extreme aspect ratios (phone screenshots past 1:2), the fixed 1024×1024 input squishes them - flip keep_aspect_ratio on for letterboxed edge-padding instead.
Inputs (9)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | 待抠图的图像,支持批量(逐张推理,避免显存峰值过高)。 RGBA 输入会自动丢弃 alpha 只取 RGB。 | |
| model_name | COMBO | 放在 models/nobg 下的模型目录(需含 config.json 与 model.safetensors)。 留空或未找到时,首次运行会自动从 HuggingFace 下载 feyninc/FeyNobg(约 1.05GB)。 | |
| resolution | COMBO | 1024 | 推理分辨率。模型原生训练分辨率为 1024,改动会影响细节与显存: 调低更省显存但边缘变粗;调高不一定更好,可能出现结构断裂。 |
| precision | COMBO | fp32 | 实测两者输出一致(同图 alpha 均值都是 0.657), 但 fp16 显存减半且明显更快,推荐优先用 fp16。 保留 fp32 作默认,是为老显卡上半精度异常时有个退路。 |
| device | COMBO | auto | auto = 有显卡就用显卡。 cpu 会慢十倍以上,仅在显存实在不够时用。 |
| alpha_thresholdopt | FLOAT | 0.500–1 | 多大置信度才算前景。模型对拿不准的区域会输出 0.5 上下的 中间值,表现为「整片主体半透明发灰」。 把阈值调低(如 0.3)可把这类区域拉回不透明。 注意:只对已有一定响应的区域有效;模型压根没认出来的 地方 alpha 接近 0,再降阈值也救不回来。 |
| alpha_softnessopt | FLOAT | 1.000–1 | 阈值两侧过渡带的宽度,决定边缘软硬。 1.0 = 完全不处理,原样输出模型结果(默认) 0.2~0.4 = 压掉灰雾但保留发丝级过渡(推荐从 0.3 试) 0 = 硬二值化,边缘变成锯齿硬边,抠玻璃/头发慎用 |
| keep_aspect_ratioopt | BOOLEAN | false | 模型固定吃 1024×1024,默认会把图直接拉伸成正方形 (与官方训练方式一致)。长图/宽图形变严重时可开启此项, 改为等比缩放 + 边缘延展补边,推理后再裁掉补边部分。 注意这与训练分布不同,属于试验性选项: 极端长宽比(如手机截图 1:2 以上)通常有改善,常规比例建议关闭。 |
| invert_maskopt | BOOLEAN | false | 反转 alpha:默认前景为白(1),开启后前景为黑。 |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| alpha | MASK | — |
| cutout | IMAGE | — |