Ultralytics YOLOv5, a PyTorch-based computer vision toolkit for object detection, instance segmentation and image classification with training and export.
ZhengPeng7/BiRefNet
Official PyTorch implementation of BiRefNet, a deep learning model for high-resolution dichotomous image segmentation, commonly used for background removal.
Open-source alternative to:Remove.bg
Adobe Photoshop Remove Background
- Stars
- 4,309
- Forks
- 344
- Open issues
- 33
- Last commit
- 3 days ago
What is it?
BiRefNet is a deep learning model for dichotomous image segmentation, which separates foreground objects from background at high resolution. The project is the official implementation of a 2024 CAAI AIR paper and provides training, testing and evaluation scripts in Python with PyTorch.
The repository offers a model zoo of pretrained weights for several tasks, including general use, portrait and general matting, DIS, HRSOD and COD. Models can be loaded in one line through Hugging Face Transformers, and ONNX conversion and FP16 inference are covered, with listed runtime and memory numbers on A100, RTX 4090 and V100 GPUs.
The project also documents fine-tuning on custom datasets, using a folder layout of images and ground-truth masks. Several community integrations exist, including ComfyUI nodes, a Stable Diffusion WebUI extension, TensorRT and GGUF conversions.
Key features
- 01Segments foreground objects at high resolution for dichotomous image segmentation tasks.
- 02Provides pretrained weights for general use, matting, portrait matting, DIS, HRSOD and COD.
- 03Loads the model in one line through Hugging Face Transformers.
- 04Includes ONNX conversion and FP16 inference with published speed and memory figures.
- 05Supports fine-tuning on custom datasets with training and evaluation scripts.
Use cases
- Removing backgrounds from product photos or portraits at high resolution.
- Building an image or video background-removal service on top of a PyTorch or ONNX model.
- Fine-tuning a segmentation model on a domain-specific dataset.
- Adding background removal as a node in ComfyUI or Stable Diffusion workflows.
Quick start
- 1
Load the BiRefNet model from Hugging Face with transformers
birefnet = AutoModelForImageSegmentation.from_pretrained('zhengpeng7/BiRefNet', trust_remote_code=True)
Things to know
- Practical use on high-resolution images generally needs a GPU, as the README's speed figures are measured on an RTX 4090.
- The project's README says it needs more GPU resources to push the model further, so some advanced variants depend on external compute.
Topics
FAQ
- What is BiRefNet?
- Official PyTorch implementation of BiRefNet, a deep learning model for high-resolution dichotomous image segmentation, commonly used for background removal. BiRefNet is a deep learning model for dichotomous image segmentation, which separates foreground objects from background at high resolution. The project is the official implementation of a 2024 CAAI AIR paper and provides training, testing and evaluation scripts in Python with PyTorch.
- Is BiRefNet free to use? What license does it have?
- BiRefNet is open source under the MIT license. Check the license terms before using it in commercial products.
- Is BiRefNet still maintained?
- Actively maintained. The last commit to BiRefNet was on Oct 17, 2026.
- What can I use BiRefNet for?
- Removing backgrounds from product photos or portraits at high resolution. Building an image or video background-removal service on top of a PyTorch or ONNX model. Fine-tuning a segmentation model on a domain-specific dataset. Adding background removal as a node in ComfyUI or Stable Diffusion workflows.
- How do I install BiRefNet?
- Load the BiRefNet model from Hugging Face with transformers: birefnet = AutoModelForImageSegmentation.from_pretrained('zhengpeng7/BiRefNet', trust_remote_code=True)
- Where can I get BiRefNet?
- The source code and installation instructions are on GitHub: https://github.com/ZhengPeng7/BiRefNet
Summary generated by AI from the project's README. GitHub stats refresh daily.
Related projects
A tool that removes image backgrounds, usable as a CLI, Python library, HTTP server, or Docker container.
Python tool for blind face restoration, enhancing blurry, low-quality or damaged faces in photos and videos using a codebook lookup transformer.
A PyTorch library implementing class activation map (CAM) methods to visualize which image regions drive a computer vision model's predictions.
A PyTorch-based open-source framework for deep learning on healthcare imaging data, covering preprocessing, networks, losses and evaluation metrics.
Open-source Python OCR library that detects and recognizes text in PDFs and images using deep learning models, built on PyTorch.