Open model workspace high-resolution vision

High-resolution segmentation with birefnet

Image-ready masks.

Sharp edges Multiple tasks MIT toolkit
Try birefnet
prompt / image
Example inputs one tap

Image-ready · one-line workflow · start in seconds

birefnet / high-resolution image segmentation
main MIT model notes
Repository files
Latest update · refreshed model guides and evaluation notes source / birefnet
File Updated
evaluation recent
models recent
tutorials recent
.gitignore recent
LICENSE recent
README.md recent
config.py recent
dataset.py recent
eval_existingOnes.py recent
gen_best_ep.py recent
image_proc.py recent
inference.py recent
loss.py recent
make_a_copy.sh recent
requirements.txt recent
rm_cache.sh recent
sub.sh recent
test.sh recent
train.py recent
train.sh recent
train_test.sh recent
utils.py recent

Bilateral Reference for High-Resolution Image Segmentation

A research-minded model workspace for sharp masks, difficult edges and repeatable visual experiments.

Journal paper Project MIT Model Multiple images Inference Box guidance
DIS-Sample_1
A traditional pavilion beside reflective water, shown as a high-contrast foreground segmentation study.
DIS-Sample_2
A radial gold ornament with fine spokes and beads, shown as a challenging high-resolution segmentation study.

This is the official birefnet workspace for Bilateral Reference for High-Resolution Dichotomous Image Segmentation, adapted here as a practical starting point for high-resolution foreground extraction, matting and related binary image tasks.

Note

High-resolution work benefits from capable hardware. The model family is designed to preserve structure as images get larger, while the surrounding toolkit keeps experiments easy to reproduce.

News 📰

  • Sep 23, 2025: The attention path was refreshed with an official PyTorch SDPA implementation to reduce memory pressure during training and inference.
  • Jun 30, 2025: Foreground refinement was accelerated with a GPU-assisted fast-estimation path and cleaner array preprocessing.
  • May 15, 2025: A recorded tutorial for fine-tuning birefnet on custom data was released for people who prefer a guided walkthrough.
  • Mar 31, 2025: The dynamic model path was expanded across resolutions from 256x256 to 2304x2304 for more robust general use.
  • Feb 12, 2025: A higher-resolution matting variant was added for workflows that need softer edges and more natural transitions.
  • Feb 1, 2025: The high-resolution general-use model was published with training centered on 2048x2048 images.
  • Jan 6, 2025: FP16 inference was validated with nearly unchanged quality and lower memory use on supported GPUs.
  • Dec 5, 2024: Compatibility fixes landed for current PyTorch compilation and accelerated mixed-precision training.
  • Nov 28, 2024: A student project built with birefnet received recognition in a national innovation competition.
  • Oct 26, 2024: The documentation gained a dedicated guide for fine-tuning existing weights on custom datasets.
  • Oct 6, 2024: Trimap-free matting weights were added for general foreground workflows.
  • Sep 24, 2024: A lightweight 2K model and a video inference notebook were published for higher-resolution inputs.
  • Aug 30, 2024: Local inference and ONNX conversion notebooks were added to the tutorials folder.
  • Aug 23, 2024: The research work was formally published online, alongside a public project release.
  • Aug 19, 2024: ONNX model files for the available weights were collected with conversion notes.
  • Jul 28, 2024: Box-guided segmentation examples were added for more controlled object selection.
  • Jul 15, 2024: One-line model loading was documented for a faster first experiment.
  • May 28, 2024: The model zoo was expanded with weights for general use, matting, DIS, HRSOD and COD.
  • May 7, 2024: A multiple-image inference notebook was published for batch experimentation.
  • Mar 7, 2024: Training code, evaluation utilities and task-specific weights were organized into the public project.
  • Jan 7, 2024: The original paper and initial implementation were released.

🚀 Load birefnet in ONE LINE

python
from transformers import AutoModelForImageSegmentation
birefnet = AutoModelForImageSegmentation.from_pretrained(
    "birefnet/model",
    trust_remote_code=True
)

🛬 Inference Partner:

You can access the birefnet inference workflow through the model workspace or use the deployment route to set up your own environment.

Our birefnet models are designed for demanding high-resolution tasks
The model family covers foreground segmentation, camouflaged-object detection, high-resolution salient-object detection, matting and guided extraction. The best checkpoint depends on the task and input resolution.

Try our online demos for inference:

A dark browser workbench showing an image input, a high-contrast foreground mask and a compact evaluation panel.

Awards:

Some strong student and community projects have been built around birefnet.
Community project recognition
A formal blue-bordered innovation award certificate on a desk, photographed front-on with a restrained academic presentation.

Model Zoo

For broader practical use, the original research implementation is extended into model variants for different image sizes, tasks and deployment constraints.

Packaged datasets and backbone weights are organized by task so experiments can begin from a known baseline.

Performance logs and predicted maps are kept alongside the corresponding experiment settings.

Models from the original paper for benchmark comparison
TaskTraining setsBackboneDownload
DISDIS5K-TRswin_v1_largemodel file
CODCOD10K-TR, CAMO-TRswin_v1_largemodel file
HRSODDUTS-TRswin_v1_largemodel file
HRSODDUTS-TR, HRSOD-TRswin_v1_largemodel file
HRSODDUTS-TR, UHRSD-TRswin_v1_largemodel file
HRSODDUTS-TR, HRSOD-TR, UHRSD-TRswin_v1_largemodel file
Models trained for general use and matting
TaskTraining setsBackboneTest setMetricDownload
general use, 2048x2048AIM-500, DIS, HIM2K, PPM-100 and high-resolution human setsswin_v1_largeDIS-VD0.927, 0.894model file
general useDIS5K, DIS-TEs, DUTS, HRSOD and UHRSDswin_v1_largeDIS-VD0.911, 0.875model file
general useDIS5K and DIS-TEsswin_v1_tinyDIS-VD0.882, 0.830model file
general mattingP3M, human, AIM-500, HIM2K and synthesized backgroundsswin_v1_largeTE-P3M0.979, 0.988model file
portrait mattingP3M and human image setsswin_v1_largeP3M-500-P0.983, 0.989model file
Segmentation with box guidance
Use a guided box to focus the segmentation on a selected region before refining the mask.
Model efficiency
RuntimeFP32FP16
A10086.8ms69.4ms
409095.8ms57.7ms
V100384ms152ms
ONNX conversion
The conversion path exports trained weights for local inference. Compatibility among runtime, CUDA and cuDNN should be checked before deployment.

Third-Party Creations

Several community applications use birefnet as a backend or node. The examples below keep the same practical, click-first spirit as the original project.

  1. Applications

    Background eraser: a compact browser workflow for removing photo backgrounds with a lightweight birefnet variant.

    Open workflow
    A pale browser interface with a background eraser upload area, soft pink accents and a clear one-click workflow.

    In-browser removal: a local-first interface keeps the image on the device while the mask is computed in the browser.

    Open workflow
    A light browser tool showing a photo upload step and a transparent-background preview, framed as a private local workflow.

    Flexible inference workflow: a visual pipeline connects image input, model configuration, refinement and output preview.

    Open workflow
    A dark node-based image workflow connecting input, model settings, mask refinement and output previews.

    ComfyUI integration: a node-based panel makes segmentation and mask conversion available inside a visual workflow.

    Open workflow
    A dark visual node editor with image input, segmentation, mask conversion and preview nodes connected across a grid.

    Video cutout service: birefnet can serve as the foreground engine for short video background-removal workflows.

    Open workflow
    A cinematic video-editing preview showing a dancer isolated on a transparent checkerboard beside the original frame.

    Invoke-style node: a simple image primitive feeds a background-removal node with optional foreground refinement.

    Open workflow
    A polished dark node graph with an image primitive connected to a remove-background node and a gallery output.

    2D asset generation: foreground extraction combines with creative tooling to produce clean cutout assets for design and previs.

    Open workflow
    A 3D design workspace showing several colorful character cutouts arranged on a reflective studio floor.

    Text-behind-subject effects: extracting the foreground makes it possible to place typography between the subject and its original scene.

    Open workflow
    A design composition with a foreground subject crossing in front of oversized white editorial lettering.

    Stable diffusion utility: a model panel adds foreground extraction to an image-generation workflow with mask and transparent output views.

    Open workflow
    A dark image-generation utility panel displaying an original fantasy portrait, a cutout subject and a white mask preview.

    Online model playground: a focused input-and-result surface exposes useful controls without requiring a local setup.

    Open workflow
    A bright model playground with an uploaded frog image on the left and a clean isolated result on the right.
  2. Model Extensions

    Anime foreground models: fine-tuned data can adapt birefnet to illustrated characters and stylized artwork where hair, ribbons and costume edges matter.

    Explore extension
    A four-row comparison grid of colorful illustrated characters shown against a teal background with foreground masks.

    Lightweight inference: alternate runtimes and compact formats make it easier to bring segmentation to consumer hardware.

    image_data image = image_load("input.png");
    backend_device device = backend_init();
    birefnet_model model = birefnet_load_model("BiRefNet-F16", device);
    image_data mask = birefnet_compute(model, image);

    Higher-quality private data: task-specific training can improve binary foreground masks, especially on varied scenes and difficult object boundaries.

    Explore extension
    A contact sheet of products, portraits, wildlife and plants shown beside transparent checkerboard cutouts.
  3. More Visual Comparisons

    Side-by-side comparisons show how birefnet behaves on product scenes, portraits and detailed foreground edges.

    A dark comparison board showing original images, birefnet masks and neighboring model results across product and portrait examples.

    Video comparisons focus on continuity, silhouette stability and preservation of small moving details.

    A video comparison frame with four labeled panels showing an animated subject isolated against a black background.

Usage

Environment Setup

# PyTorch >= 2.5.0 is used for faster training with compilation.
conda create -n birefnet python=3.11 -y && conda activate birefnet
pip install -r requirements.txt

Dataset Preparation

Download the combined training and test sets organized for DIS, COD and HRSOD, or use the official source datasets in the single_ones folder. Keep image and ground-truth folders aligned inside each task.

Weights Preparation

Download backbone weights from the model workspace or their official project pages before launching training or local inference.

Run

# Train & Test & Evaluation
./train_test.sh RUN_NAME GPU_NUMBERS_FOR_TRAINING GPU_NUMBERS_FOR_TEST
# Example: ./train_test.sh tmp-proj 0,1,2,3 0

# See train.sh / test.sh for only training or evaluation.
# After evaluation, use gen_best_ep.py to select the best checkpoint.

🖊️ Fine-tuning on Custom Data

A recorded tutorial explains the birefnet fine-tuning path from dataset layout to checkpoint selection.
A clean tutorial cover showing a high-resolution segmentation title, two image examples and compact project badges.
  1. Pre-requisites: place datasets at ${data_root_dir}/TASK_NAME/DATASET_NAME, with im and gt folders inside each dataset.
  2. Change an existing task: replace the existing task name throughout the project with your custom task name.
  3. Adapt settings: update sys_home_dir, testsets, training_set and the loss weights for your task.
  4. Use existing weights: resume from a checkpoint and continue the epoch range from the number encoded in the file name.
  5. Validate the result: compare masks on the validation set before promoting a checkpoint to a production workflow.

Well-trained weights:

Download the BiRefNet-{TASK}-{EPOCH}.pth files from the model workspace and release collection. Predicted maps, performance summaries and training logs live beside the corresponding experiment settings.

The results can vary slightly with hardware and training configuration. A single capable GPU can be enough for inference at 1024x1024, while higher-resolution training benefits from additional memory.

When more GPUs are available, increase the batch size and configure the device IDs in config.py to move smoothly from single-card to multi-card training.

Some of my messages:

This project began as a DIS implementation and grew into a broader toolkit for binary image segmentation. It can support DIS, COD, SOD, medical imagery and anomaly segmentation when the task configuration is adapted carefully.

  • Multi-GPU training can be opened or closed with a single setting.
  • Backbone choices include Swin variants, PVT variants and convolutional networks.
  • Weighted losses include BCE, IoU, SSIM, MAE and regression-oriented terms.
  • Training tricks include multi-scale supervision, backbone freezing and multi-scale inputs.
  • The data collator can combine datasets in memory for coordinated training and testing.
  • The goal is a reusable foundation for new visual segmentation work.

Quantitative Results

Benchmark summaries compare birefnet with established methods across high-resolution and low-resolution datasets.

A research-style results board with dense benchmark tables comparing segmentation metrics across several datasets.
Test setStructure scoreWeighted F scoreMAEHCE
DIS-TE10.8600.8190.037106
DIS-TE20.8940.8570.036266
DIS-TE30.9250.8930.028569
DIS-VD0.8910.8540.038989

Qualitative Results

Visual comparisons focus on narrow structures, partial occlusion, repeated patterns and camouflage.

A tiled qualitative comparison showing input scenes, ground truth masks, birefnet outputs and neighboring methods on difficult foreground examples.

Acknowledgement:

Many thanks to the companies, institutes and community contributors who help make high-resolution visual research more accessible.

Citation

@article{birefnet2024,
  title={Bilateral Reference for High-Resolution Dichotomous Image Segmentation},
  author={Birefnet Research Team},
  journal={CAAI Artificial Intelligence Research},
  volume={3},
  pages={9150038},
  year={2024}
}

Contact

Questions, discussions and implementation notes can be shared through the project workspace. For a guided start, use the birefnet workflow and bring your own image or prompt.

MIT license

The project documentation and core implementation are presented under the MIT license. Review the accompanying license file before using any model weights or third-party extensions.

Start creating
Start creating