How to remove image backgrounds with BiRefNet on a cloud GPU

Rent a GPU on Deploy, then open a terminal in JupyterLab or over SSH. Install BiRefNet from the official ZhengPeng7/BiRefNet repository, load ZhengPeng7/BiRefNet the way the model card prints, and run the documented inference function. Copy the image off the instance before you destroy it, because destroying the instance deletes its disk.

Promptable segmentation is a different repository: How to run SAM 2 (Segment Anything 2) on a cloud GPU. Relighting from the IC-Light README, which names this repository as one replacement for its background model, is How to run IC-Light on a cloud GPU. Image and video upscaling is How to upscale images and video with Real-ESRGAN on a cloud GPU. How published FLUX and SDXL weight sizes are read: How much VRAM do I need for FLUX and SDXL. If the process raises an out-of-memory error: How to fix CUDA out of memory on a cloud GPU.

The repository LICENSE file is the MIT License, copyright © 2024 ZhengPeng. The GitHub license field on 2026-11-13 was MIT. The model card for ZhengPeng7/BiRefNet the same day had license mit and gated false, lastModified 2026-02-04T22:43:55.000Z. Read the LICENSE file before you redistribute the program or the weights.

The commands below are copied from the upstream files named in each step. They were not run on a CloudGPU instance for this page. Anything this page adds around them is marked.

What the README says about memory

The README prints more than one inference memory figure. The Jan 6, 2025 news line says the standard BiRefNet can run in 17 FPS with resolution==1024x1024 with 3.45GB GPU memory on a single RTX 4090. The efficiency table’s GPU Memory rows, copied:

GPU Memory FP32 FP16/BF16
Inference 4.8GB 3.5GB
Training (#GPU=2, batch_size=2, compile=False+PyTorch=2.8.0) 38.2GB (A100) 28.5GB (A100)
Training (#GPU=2, batch_size=2, compile=True+PyTorch=2.8.0) 35.6GB (A100) 23.5GB (4090), 23.9GB (A100)

The README says the devices in that table differ from the original paper, and that the table is only for reference. A later paragraph says “5.5G GPU memory is needed for inference in 1024x1024” and that you can train on a single GPU with “36.5G+ memory”. The training rows and the 36.5G+ sentence are training figures. The model card read 2026-11-13 prints no GB figure. This page did not remeasure any of these cells.

GET /v1/public/compute-capabilities does not list GPUs. It returns feature flags. The memory column is vram_gb from gpu-prices.json, updated_at 2026-11-13T06:05:49.853Z. GET /v1/public/gpu-catalog the same day (generated_at 2026-11-13T06:05:50.927Z) listed the same names and the same vram_gb values, plus Ascend 910B at 64, which is not in gpu-prices.json and is not listed here. The catalog response also includes an availability field. This page does not copy it. Every prices row has gpu_count 1. The news line names a single RTX 4090. The training cells name A100 and 4090, and they do not say which A100 memory size. Catalog RTX 4090 is 24. Catalog A100 40G is 40 and A100 80G is 80. Those catalog numbers are not the cells above. Every listed vram_gb is 8 or higher, so each one is greater than the 5.5G inference sentence. The rows at 8, 10, 11, 12, 16, 24, and 32 are below the 36.5G+ training sentence. The rows at 40 and above are greater than 36.5. This page did not run BiRefNet and does not mark a row as enough for inference or for training. Which listing you can start is on Deploy.

The catalog template list had no BiRefNet template.

Catalog name vram_gb
RTX 2080 8
RTX 3080 10
RTX 2080 Ti 11
RTX 3080 Ti 12
V100 16G 16
A30 24
RTX 3090 24
RTX 4090 24
RTX 4090D 24
RTX 4080 SUPER 32G 32
RTX 5090 32
RTX 5090D 32
V100 32G 32
A100 40G 40
A800 40G 40
A40 48
RTX 4090 48G 48
RTX 4090D 48G 48
RTX A6000 48
NVIDIA RTX PRO 5000 72G 72
RTX PRO 5000 72G 72
A100 80G 80
A800 80G 80
H800 80
RTX 6000D 83
H20 96G 96
RTX PRO 6000 96G 96
RTX PRO 6000 Max-Q 96
H20-3e 141G 141

The Jun 30, 2025 news line says refine_foreground is ~80ms on a 5090. This page did not remeasure that. Catalog RTX 5090 is 32. That is the catalog number, not the news line.

Install

On Deploy, choose Raw GPU. The README environment block is:

# PyTorch>=2.5.0 (I try to make everything as latest as possible) is used for faster training (~40%) with compilation.
conda create -n birefnet python=3.11 -y && conda activate birefnet
pip install -r requirements.txt

requirements.txt starts with torch>=2.5.0 and torchvision, then numpy<2, and does not print a CUDA index. This page did not check whether conda is on the Raw GPU image, and it did not pick a torch wheel. How to install a specific PyTorch CUDA version is the index check against the CUDA Version in the nvidia-smi header. The commits API for the default branch main listed f7079632d681ecf12161fcea8905682934e59e51, committed 2026-10-25T20:40:32Z. requirements.txt was afe09e0f372be458ae4f5d84499e30e2b66d4fe6, committed 2025-09-25T17:53:43Z.

The model card’s install line, copied:

pip install -qr https://raw.githubusercontent.com/ZhengPeng7/BiRefNet/main/requirements.txt

Documented inference

The README’s one-line load uses a different capitalization from the model card. Copied from the README:

from transformers import AutoModelForImageSegmentation
birefnet = AutoModelForImageSegmentation.from_pretrained('zhengpeng7/BiRefNet', trust_remote_code=True)

The model card’s Hugging Face load, copied:

from transformers import AutoModelForImageSegmentation
birefnet = AutoModelForImageSegmentation.from_pretrained('ZhengPeng7/BiRefNet', trust_remote_code=True)

The same card also prints a clone, then BiRefNet.from_pretrained('ZhengPeng7/BiRefNet'). After whichever load you used, the card’s inference block moves that model to CUDA and half precision before the function. Copied. The birefnet = ... line is the card’s placeholder for one of the load blocks above. imagepath is the card’s placeholder.

birefnet = ... # -- BiRefNet should be loaded with codes above, either way.
torch.set_float32_matmul_precision(['high', 'highest'][0])
birefnet.to('cuda')
birefnet.eval()
birefnet.half()

def extract_object(birefnet, imagepath):
    # Data settings
    image_size = (1024, 1024)
    transform_image = transforms.Compose([
        transforms.Resize(image_size),
        transforms.ToTensor(),
        transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
    ])

    image = Image.open(imagepath)
    input_images = transform_image(image).unsqueeze(0).to('cuda').half()

    # Prediction
    with torch.no_grad():
        preds = birefnet(input_images)[-1].sigmoid().cpu()
    pred = preds[0].squeeze()
    pred_pil = transforms.ToPILImage()(pred)
    mask = pred_pil.resize(image.size)
    image.putalpha(mask)
    return image, mask

The same block imports PIL.Image, matplotlib.pyplot, torch, torchvision.transforms, and models.birefnet.BiRefNet. That last import is for the local-code load. The transformers load above does not use it. The card then calls plt.imshow on the returned image and plt.show(). It does not call save, and it does not loop a directory. image.putalpha(mask) is how that function attaches the mask. This page did not run it.

inference.py is the repository’s test script. Its --pred_root default is e_preds. It loops args.testsets, and the default for that argument is config.testsets. config.py sets self.task to DIS5K and the DIS5K test-set string is sliced to the first name, DIS-VD. save_tensor_img converts the tensor with ToPILImage and calls save on the original filename. It does not add a .png suffix of its own. config.py sets self.size to (1024, 1024) for that default task, self.mixed_precision to the third entry of ['no', 'fp16', 'bf16', 'fp8'] (bf16), self.device to 0, and self.batch_size_valid to 1. The model card calls birefnet.half() before extract_object, and the function also calls .half() on the input tensor. Those are separate files. The commits API listed inference.py at afe09e0f372be458ae4f5d84499e30e2b66d4fe6 (2025-09-25T17:53:43Z), utils.py at 8dac6b0447b873729651bc3be40dbb79ea982315 (2025-02-11T09:57:11Z), and config.py at 32c1dcd22f749247fa142718d57528142baa93a9 (2025-10-09T15:32:54Z). This page did not run inference.py.

The README links a Colab whose badge text is “Multiple Images Inference”. This page did not copy cells from that Colab and does not add a folder loop the README does not print.

ComfyUI

The README says ComfyUI has an official integration and links https://blog.comfy.org/p/new-open-source-models-now-in-comfyui. Read on 2026-11-13, that page’s BiRefNet getting-started lines say to download the package from Comfy-Org/BiRefNet and place birefnet.safetensors in models/background_removal/. A request for https://github.com/Comfy-Org/BiRefNet the same day returned HTTP 404. The Hugging Face model API for Comfy-Org/BiRefNet returned HTTP 200. That card had license mit, gated false, lastModified 2026-10-28T02:38:00.000Z, and base_model including ZhengPeng7/BiRefNet. Its file list included background_removal/birefnet.safetensors and background_removal/lucida.safetensors. The card’s folder tree puts both names under ComfyUI/models/background_removal/. The workflow link on the card is https://github.com/Comfy-Org/workflow_templates/blob/main/templates/utility_birefnet_remove_background.json. This page did not download the weights and did not open the workflow. Installing ComfyUI itself is How to install ComfyUI and ComfyUI-Manager on a cloud GPU.

The repository file list on 2026-11-13 had no Gradio app. The README links a Hugging Face Space for an online demo. That Space is not a port on the rented machine. This page does not add an SSH forward for it. The ComfyUI examples top-level directory list the same day had no BiRefNet directory. Examples HEAD was f9431bb000ce792094ff345446e22cac1ea6cef3, committed 2025-11-26T20:33:58Z.

When it fails

CUDA out of memory. The README prints the inference figures above and no flag that lowers them. If the process raises that error, use how to fix CUDA out of memory on a cloud GPU.

“CUDA error: no kernel image is available for execution on the device” on an RTX 5090. requirements.txt requires torch>=2.5.0 and does not name compute capability 12.0. The RTX 5090 guide says that card is compute capability 12.0 (sm_120) and that PyTorch 2.7 and later, on a build for CUDA 12.8 or newer, is the line that announced support. This page did not install a torch wheel and did not re-test this package on an RTX 5090. Catalog RTX 5090 and RTX 5090D are 32. That is the catalog number only.

Save the image, then destroy

The model card returns the image from extract_object and does not write a path. inference.py writes under e_preds unless you pass --pred_root. Copy whichever file you write before you destroy the instance. Save your work before you destroy a cloud GPU is the checklist. The terms say data on local instance storage is permanently deleted when the instance is destroyed.

The pricing page FAQ states the billing rule in these words:

Per-minute options have a 1-minute minimum; unused prepaid minutes are refunded when you destroy the instance. Some configurations use whole-hour billing with a 1-hour minimum; unused time within a charged hour is not refunded on voluntary stop. The billing period, minimum charge and initial prepayment are shown before confirmation. No subscription.

Frequently asked questions

Which GPU memory figures does the BiRefNet README print?

The Jan 6, 2025 news line says the standard BiRefNet can run in 17 FPS at resolution 1024x1024 with 3.45GB GPU memory on a single RTX 4090. The efficiency table’s GPU Memory rows say inference is 4.8GB in FP32 and 3.5GB in FP16/BF16. A later paragraph says 5.5G GPU memory is needed for inference in 1024x1024. The same paragraph says training can be done on a single GPU with 36.5G+ memory. The training rows in the table print 38.2GB, 28.5GB, 35.6GB, 23.5GB, and 23.9GB with the GPU names and settings in that table. The model card read 2026-11-13 prints no GB figure. This page did not remeasure any of these and does not mark a catalog row as enough. Which listing you can start is on https://cloudgpu.app/deploy.

Which license covers the BiRefNet code and the ZhengPeng7/BiRefNet weights?

The repository LICENSE file is the MIT License, copyright © 2024 ZhengPeng. The GitHub license field on 2026-11-13 was MIT. The model card for ZhengPeng7/BiRefNet the same day had license mit and gated false. Those files agree on MIT. Read the LICENSE file before you redistribute the program or the weights.

Does the documented inference save a transparent PNG for a folder of images?

The model card calls birefnet.to(‘cuda’), birefnet.eval(), and birefnet.half() before extract_object. That function takes one image path, moves the input to CUDA in float16, resizes the mask to the image size, and calls image.putalpha(mask). The snippet shows the result with plt.show() and does not call save. It does not loop a directory. inference.py loops a configured test set and save_tensor_img writes a PIL image to the original filename under --pred_root, whose default is e_preds. The README links a Colab whose badge text is Multiple Images Inference. This page did not copy cells from that Colab and did not add a folder loop.

Does the BiRefNet repository ship a local web UI?

The repository file list on 2026-11-13 had no Gradio app. The README links a Hugging Face Space for an online demo. That Space is not a port on the rented machine. The README says ComfyUI has an official integration and links a ComfyUI blog. The Comfy-Org/BiRefNet model card says to place birefnet.safetensors under models/background_removal/ and links a remove-background workflow. This page did not install that workflow.

Sources (read 2026-11-13, Asia/Shanghai)

  • ZhengPeng7/BiRefNet README (conda install, one-line load zhengpeng7/BiRefNet, Jan 6 2025 3.45GB / 17 FPS line, efficiency table, 5.5G and 36.5G+ sentences, Jun 30 2025 ~80ms line, ComfyUI blog link, Multiple Images Inference Colab, MIT badge): https://github.com/ZhengPeng7/BiRefNet/blob/main/README.md commit f7079632d681ecf12161fcea8905682934e59e51. That commit is also repository HEAD, 2026-10-25T20:40:32Z
  • requirements.txt (torch>=2.5.0, numpy<2): commit afe09e0f372be458ae4f5d84499e30e2b66d4fe6
  • inference.py (--pred_root default e_preds): same commit
  • utils.py (save_tensor_img uses ToPILImage and save): commit 8dac6b0447b873729651bc3be40dbb79ea982315
  • config.py (default task DIS5K, test set DIS-VD, size (1024, 1024), mixed_precision index bf16): commit 32c1dcd22f749247fa142718d57528142baa93a9
  • LICENSE (MIT, copyright © 2024 ZhengPeng): commit 2713d1293ce8a923d5878f1f30177b78770bf24c. GitHub license field MIT
  • Model card ZhengPeng7/BiRefNet (license mit, gated false, extract_object, putalpha, no GB figure): https://huggingface.co/ZhengPeng7/BiRefNet read 2026-11-13, lastModified 2026-02-04T22:43:55.000Z
  • ComfyUI blog BiRefNet getting-started lines (Comfy-Org/BiRefNet, birefnet.safetensors, models/background_removal/): https://blog.comfy.org/p/new-open-source-models-now-in-comfyui read 2026-11-13. https://github.com/Comfy-Org/BiRefNet returned HTTP 404 the same day
  • Model card Comfy-Org/BiRefNet (license mit, background_removal/birefnet.safetensors, background_removal/lucida.safetensors, workflow utility_birefnet_remove_background.json): https://huggingface.co/Comfy-Org/BiRefNet read 2026-11-13, lastModified 2026-10-28T02:38:00.000Z
  • ComfyUI examples top-level directories (no BiRefNet directory): https://github.com/comfyanonymous/ComfyUI_examples commit f9431bb000ce792094ff345446e22cac1ea6cef3
  • Public GPU memory: https://cloudgpu.app/gpu-prices.json (updated_at 2026-11-13T06:05:49.853Z) and https://cloudgpu.app/v1/public/gpu-catalog (generated_at 2026-11-13T06:05:50.927Z). GET /v1/public/compute-capabilities returned feature flags and no GPU list. The catalog had no BiRefNet template

Cards you can start are on the Deploy page. Prices are on https://cloudgpu.app/pricing and are not repeated here.

Last updated: 2026-11-13 (Asia/Shanghai).