Comfy-Org / Comfy-Org/ComfyUI

Remove Background (BiRefNet) bug?

Open
#15,956 0 comments 0 reactions 0 assignees View on GitHub
Potential Bug
Dominant language
Python
Stars
133k
Forks
15.7k
Avg merge
1d 6h
Merged PRs (30d)
155

Description

### Custom Node Testing

- [x] I have tried disabling custom nodes and the issue persists (see [how to disable custom nodes](https://docs.comfy.org/troubleshooting/custom-node-issues#step-1%3A-test-with-all-custom-nodes-disabled) if you need help)

### Expected Behavior

Removing the background output image preview is normal, but when connected to other nodes such as VAE encoding, the background should be removed.

### Actual Behavior

Removing the background output image preview is normal, but connecting to other nodes does not remove the background (such as VAE encoding). What's even more outrageous is that after re uploading the image with the background removed, VAE decoding actually completes the background.

Image

### Steps to Reproduce

[Remove Background (BiRefNet).json](https://github.com/user-attachments/files/31580025/Remove.Background.BiRefNet.json)

### Debug Logs

```powershell
[DEBUG] STREAM b'IHDR' 16 13
[DEBUG] STREAM b'tEXt' 41 1755
[DEBUG] STREAM b'tEXt' 1808 9834
[DEBUG] STREAM b'IDAT' 11654 65536
[INFO] Seeder start (roots=('output',), phase=enrich)
[INFO] Asset scan [output] directories: ['H:\\AI\\ComfyUI\\output']
[INFO] Scan(('output',), enrich) done 0.001s: created=0 enriched=0 skipped=0
[DEBUG] tag: Orientation (274) - type: short (3) - value: b'\x00\x01'
[DEBUG] tag: ExifIFD (34665) - type: long (4) - value: b'\x00\x00\x00&'
[DEBUG] tag: Orientation (274) - type: short (3) - value: b'\x00\x01'
[DEBUG] tag: ExifIFD (34665) - type: long (4) - value: b'\x00\x00\x00&'
[INFO] got prompt
[DEBUG] Using proactor: IocpProactor
[DEBUG] aimdo: src/control.c:184:DEBUG:--- VRAM Stats ---
[DEBUG] aimdo: src/control.c:193:DEBUG: Aimdo Recorded Usage: 23 MB
[DEBUG] aimdo: src/control.c:194:DEBUG: Device: 22263 MB / 24564 MB Free
[DEBUG] aimdo: src/model-vbar.c:302:DEBUG:vbar_prioritize vbar=000001D31BEFB820
[DEBUG] aimdo: src-win/shmem-detect.c:131:DEBUG:poll_budget_deficit: WDDM budget=23370 MB usage=496 MB reservation=0 MB available=11813 MB
[DEBUG] aimdo: src-win/shmem-detect.c:149:DEBUG:poll_budget_deficit: device memory free=22262 MB total=24564 MB deficit_cuda=-21750 MB
[DEBUG] aimdo: src-win/shmem-detect.c:157:DEBUG:poll_budget_deficit: prevailing method NVML (Windows)
[INFO] Model BiRefNet prepared for dynamic VRAM loading. 419MB Staged. 0 patches attached. Force pre-loaded 268 weights: 4216 KB.
[DETAIL] Model loaded: patcher=ModelPatcherDynamic model=BiRefNet ram_mb=419.2 vram_mb=4.1
[DEBUG] aimdo: src/control.c:184:DEBUG:--- VRAM Stats ---
[DEBUG] aimdo: src/control.c:193:DEBUG: Aimdo Recorded Usage: 471 MB
[DEBUG] aimdo: src/control.c:194:DEBUG: Device: 18833 MB / 24564 MB Free
[DEBUG] aimdo: src/model-vbar.c:57:DEBUG:---------------- VBAR Usage ---------------
[DEBUG] aimdo: src/model-vbar.c:87:DEBUG:VBAR 000001D439B2D0E0: Actual Resident VRAM = 0 MB
[DEBUG] aimdo: src/model-vbar.c:87:DEBUG:VBAR 000001D31BEFB820: Actual Resident VRAM = 448 MB
[DEBUG] aimdo: src/model-vbar.c:90:DEBUG:Total VRAM for VBARs: 448 MB
[DEBUG] aimdo: src/control.c:184:DEBUG:--- VRAM Stats ---
[DEBUG] aimdo: src/control.c:193:DEBUG: Aimdo Recorded Usage: 471 MB
[DEBUG] aimdo: src/control.c:194:DEBUG: Device: 21809 MB / 24564 MB Free
[DEBUG] aimdo: src/control.c:184:DEBUG:--- VRAM Stats ---
[DEBUG] aimdo: src/control.c:193:DEBUG: Aimdo Recorded Usage: 471 MB
[DEBUG] aimdo: src/control.c:194:DEBUG: Device: 21808 MB / 24564 MB Free
[DEBUG] STREAM b'IHDR' 16 13
[DEBUG] STREAM b'tEXt' 41 1755
[DEBUG] STREAM b'tEXt' 1808 9834
[DEBUG] STREAM b'IDAT' 11654 65536
[DEBUG] aimdo: src/control.c:184:DEBUG:--- VRAM Stats ---
[DEBUG] aimdo: src/control.c:193:DEBUG: Aimdo Recorded Usage: 471 MB
[DEBUG] aimdo: src/control.c:194:DEBUG: Device: 21808 MB / 24564 MB Free
[DEBUG] aimdo: src/control.c:184:DEBUG:--- VRAM Stats ---
[DEBUG] aimdo: src/control.c:193:DEBUG: Aimdo Recorded Usage: 471 MB
[DEBUG] aimdo: src/control.c:194:DEBUG: Device: 21808 MB / 24564 MB Free
[DEBUG] STREAM b'IHDR' 16 13
[DEBUG] STREAM b'tEXt' 41 1755
[DEBUG] STREAM b'tEXt' 1808 9834
[DEBUG] STREAM b'IDAT' 11654 65536
[DEBUG] aimdo: src/control.c:184:DEBUG:--- VRAM Stats ---
[DEBUG] aimdo: src/control.c:193:DEBUG: Aimdo Recorded Usage: 471 MB
[DEBUG] aimdo: src/control.c:194:DEBUG: Device: 21807 MB / 24564 MB Free
[DEBUG] STREAM b'IHDR' 16 13
[DEBUG] STREAM b'tEXt' 41 1755
[DEBUG] STREAM b'tEXt' 1808 9834
[DEBUG] STREAM b'IDAT' 11654 65536
[DEBUG] aimdo: src/model-vbar.c:302:DEBUG:vbar_prioritize vbar=000001D439B2D0E0
[INFO] Model AutoencoderKL prepared for dynamic VRAM loading. 160MB Staged. 0 patches attached. Force pre-loaded 110 weights: 187 KB.
[DETAIL] Model loaded: patcher=ModelPatcherDynamic model=AutoencoderKL ram_mb=320.4 vram_mb=0.2
[DEBUG] aimdo: src/model-vbar.c:57:DEBUG:---------------- VBAR Usage ---------------
[DEBUG] aimdo: src/model-vbar.c:87:DEBUG:VBAR 000001D31BEFB820: Actual Resident VRAM = 448 MB
[DEBUG] aimdo: src/model-vbar.c:87:DEBUG:VBAR 000001D439B2D0E0: Actual Resident VRAM = 0 MB
[DEBUG] aimdo: src/model-vbar.c:90:DEBUG:Total VRAM for VBARs: 448 MB
[DEBUG] STREAM b'IHDR' 16 13
[DEBUG] STREAM b'tEXt' 41 1755
[DEBUG] STREAM b'tEXt' 1808 9834
[DEBUG] STREAM b'IDAT' 11654 65536
[DEBUG] aimdo: src/control.c:184:DEBUG:--- VRAM Stats ---
[DEBUG] aimdo: src/control.c:193:DEBUG: Aimdo Recorded Usage: 663 MB
[DEBUG] aimdo: src/control.c:194:DEBUG: Device: 18510 MB / 24564 MB Free
[DEBUG] aimdo: src/model-vbar.c:57:DEBUG:---------------- VBAR Usage ---------------
[DEBUG] aimdo: src/model-vbar.c:87:DEBUG:VBAR 000001D31BEFB820: Actual Resident VRAM = 448 MB
[DEBUG] aimdo: src/model-vbar.c:87:DEBUG:VBAR 000001D439B2D0E0: Actual Resident VRAM = 160 MB
[DEBUG] aimdo: src/model-vbar.c:90:DEBUG:Total VRAM for VBARs: 608 MB
[DEBUG] aimdo: src/model-vbar.c:302:DEBUG:vbar_prioritize vbar=000001D439B2D0E0
[INFO] Model AutoencoderKL prepared for dynamic VRAM loading. 160MB Staged. 0 patches attached. Force pre-loaded 110 weights: 187 KB.
[DETAIL] Model loaded: patcher=ModelPatcherDynamic model=AutoencoderKL ram_mb=320.4 vram_mb=160.2
[DEBUG] aimdo: src/model-vbar.c:57:DEBUG:---------------- VBAR Usage ---------------
[DEBUG] aimdo: src/model-vbar.c:87:DEBUG:VBAR 000001D31BEFB820: Actual Resident VRAM = 448 MB
[DEBUG] aimdo: src/model-vbar.c:87:DEBUG:VBAR 000001D439B2D0E0: Actual Resident VRAM = 160 MB
[DEBUG] aimdo: src/model-vbar.c:90:DEBUG:Total VRAM for VBARs: 608 MB
[DEBUG] aimdo: src/control.c:184:DEBUG:--- VRAM Stats ---
[DEBUG] aimdo: src/control.c:193:DEBUG: Aimdo Recorded Usage: 695 MB
[DEBUG] aimdo: src/control.c:194:DEBUG: Device: 15056 MB / 24564 MB Free
[DEBUG] aimdo: src/model-vbar.c:57:DEBUG:---------------- VBAR Usage ---------------
[DEBUG] aimdo: src/model-vbar.c:87:DEBUG:VBAR 000001D31BEFB820: Actual Resident VRAM = 448 MB
[DEBUG] aimdo: src/model-vbar.c:87:DEBUG:VBAR 000001D439B2D0E0: Actual Resident VRAM = 192 MB
[DEBUG] aimdo: src/model-vbar.c:90:DEBUG:Total VRAM for VBARs: 640 MB
[DEBUG] aimdo: src/control.c:184:DEBUG:--- VRAM Stats ---
[DEBUG] aimdo: src/control.c:193:DEBUG: Aimdo Recorded Usage: 663 MB
[DEBUG] aimdo: src/control.c:194:DEBUG: Device: 21616 MB / 24564 MB Free
[DEBUG] STREAM b'IHDR' 16 13
[DEBUG] STREAM b'tEXt' 41 1755
[DEBUG] STREAM b'tEXt' 1808 9834
[DEBUG] STREAM b'IDAT' 11654 65536
[DETAIL] RAM cache evictions: prompt=18a371f9-58be-465a-bacb-f4fb34a8cd95 active=False full=False
[INFO] Prompt executed in 2.34 seconds
```

### Other

使用的版本是0.34.1,并且为了排除缓存问题重启->运行了好几次都一样还是不行。

Contributor guide

Open the contributing guide

Research direction

Start by importing the attached Remove Background (BiRefNet).json workflow and reproducing the result with ComfyUI 0.34.1, comparing the output before and after VAE encoding and decoding. Trace how the Remove Background (BiRefNet) output is passed into the VAE nodes; done means the background remains removed through the connected workflow and after re-uploading the result.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
computer-vision, machine-learning
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.