Run this model with HF Jobs

Run ZhengPeng7/BiRefNet-V2-DIS5K on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.

Paste one of these prompts into your coding agent:

Fine-tune on my dataset

Use HF Jobs to fine-tune https://huggingface.co/ZhengPeng7/BiRefNet-V2-DIS5K. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.

Run batch inference

Use HF Jobs to run batch inference with https://huggingface.co/ZhengPeng7/BiRefNet-V2-DIS5K on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.

BiRefNet-V2-DIS5K

BiRefNet-V2 with a DINOv3-L backbone for dichotomous image segmentation (DIS), trained on DIS5K-TR. It is one of the checkpoints of the paper "BiRefNet-V2: Rethinking Bilateral Reference for High-Resolution Dichotomous Image Segmentation" (arXiv:2611.11272).

Code, the other checkpoints and the full result tables: https://github.com/ZhengPeng7/BiRefNet-V2

Results

Results of these weights on the test sets of the task, copied from the evaluation logs released with the checkpoint (row fish_d_2--epoch_32). Higher is better except for MAE and HCE.

Test set max F weighted F MAE S-measure mean E HCE
DIS-TE1 .914 .890 .022 .927 .949 94
DIS-TE2 .939 .915 .020 .940 .960 225
DIS-TE3 .951 .926 .019 .942 .968 473
DIS-TE4 .939 .908 .027 .933 .959 2150
DIS-VD .932 .907 .024 .935 .956 731

The test sets:

Test set Images Description Paper License of the data
DIS-TE1 500 Test images of DIS5K, subset 1 of 4 in ascending order of shape complexity. ECCV 2022 DIS5K Terms of Use: non-commercial research or education, no redistribution
DIS-TE2 500 Test images of DIS5K, subset 2 of 4 in ascending order of shape complexity. ECCV 2022 DIS5K Terms of Use: non-commercial research or education, no redistribution
DIS-TE3 500 Test images of DIS5K, subset 3 of 4 in ascending order of shape complexity. ECCV 2022 DIS5K Terms of Use: non-commercial research or education, no redistribution
DIS-TE4 500 Test images of DIS5K, subset 4 of 4 in ascending order of shape complexity. ECCV 2022 DIS5K Terms of Use: non-commercial research or education, no redistribution
DIS-VD 470 Validation set of DIS5K. ECCV 2022 DIS5K Terms of Use: non-commercial research or education, no redistribution

License of the data is what the authors of a dataset state for its data, with a link to their statement, or to the official page where they state none.

Training

Trained on DIS5K-TR for 50 epochs, the schedule of scripts/train.sh of the code repository for this task; these are the weights saved at epoch 32. The training set:

Training set Images Description Paper License of the data
DIS5K-TR 3,000 Training set of DIS5K, high-resolution images (2K, 4K or larger) of camouflaged, salient or meticulous objects with highly accurate binary masks. ECCV 2022 DIS5K Terms of Use: non-commercial research or education, no redistribution

How to use

from transformers import AutoModelForImageSegmentation
model = AutoModelForImageSegmentation.from_pretrained('ZhengPeng7/BiRefNet-V2-DIS5K', trust_remote_code=True)

model.safetensors holds the whole model, backbone and decoder, so nothing else is downloaded and the model then works offline. Packages needed: torch, torchvision, timm (1.0.23 or newer), transformers and einops; for the full environment, see the GitHub repository. requirements.txt pins the versions this repository was verified with (torch==2.14.1, torchvision==0.29.1, timm==1.0.30, transformers==5.14.1, einops==0.8.2); it is a reference, and only Hugging Face Inference Endpoints installs it automatically.

A complete example on one image:

import torch
from PIL import Image
from torchvision import transforms
from transformers import AutoModelForImageSegmentation

model = AutoModelForImageSegmentation.from_pretrained('ZhengPeng7/BiRefNet-V2-DIS5K', trust_remote_code=True)
model.to('cuda').eval()

image = Image.open('your_image.jpg').convert('RGB')
transform = transforms.Compose([
    transforms.Resize(model.config.size[::-1]),   # model.config.size is (W, H): 1024x1024
    transforms.ToTensor(),
    transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225]),
])
inputs = transform(image).unsqueeze(0).to('cuda')

with torch.no_grad():
    pred = model(inputs)[-1].sigmoid()   # 1 x 1 x H x W, values in [0, 1]

mask = transforms.functional.to_pil_image(pred[0].cpu()).resize(image.size)
mask.save('your_image_mask.png')
image.putalpha(mask)
image.save('your_image_foreground.png')

On a GPU the model runs under bfloat16 autocast by itself, the precision it was trained and evaluated in, so nothing has to be added around it. Keep the model and its input in float32, as loaded: model.half() is refused, since float16 gives NaN outputs.

The model works at model.config.size and resizes its input to that size internally. To run it at another resolution, set both sizes before the forward pass, each side a multiple of 32:

model.config.size = model.config.ir_size = [2048, 2048]   # (W, H)

Files

File Content
model.safetensors the weights of the whole model, backbone and decoder: the tensors of the released checkpoint BiRefNet-V2-DIS-epoch_32.pth, unchanged (bf16)
config.json the architecture settings of this checkpoint
configuration_birefnet_v2.py, modeling_birefnet_v2.py, blocks_birefnet_v2.py the model code that trust_remote_code=True loads: the inference part of the code repository
handler.py, requirements.txt custom handler for Hugging Face Inference Endpoints, and the packages it and the model code need
LICENSE-DINOv3.md the DINOv3 License, which the use of these weights must also follow

The checkpoint file itself, the prediction maps of this checkpoint on every test set, its evaluation logs and its training log are in the Google Drive folder of BiRefNet-V2; the checkpoint file is also attached to the weights release of the code repository.

License

Everything we release for BiRefNet-V2 -- the code, the models and the weights -- is under the MIT License. Since BiRefNet-V2 uses the DINOv3 weights for its backbone, the use of the weights in this repository must also follow the DINOv3 License (LICENSE-DINOv3.md).

Citation

@article{zheng2026birefnetv2,
  title={BiRefNet-V2: Rethinking Bilateral Reference for High-Resolution Dichotomous Image Segmentation},
  author={Zheng, Peng and Fan, Deng-Ping and Wang, Binglu and Sebe, Nicu},
  journal={arXiv preprint arXiv:2611.11272},
  year={2026}
}

@article{zheng2024birefnet,
  title={Bilateral Reference for High-Resolution Dichotomous Image Segmentation},
  author={Zheng, Peng and Gao, Dehong and Fan, Deng-Ping and Liu, Li and Laaksonen, Jorma and Ouyang, Wanli and Sebe, Nicu},
  journal={CAAI Artificial Intelligence Research},
  volume={3},
  pages={9150038},
  year={2024}
}
Downloads last month
-
Safetensors
Model size
0.3B params
Tensor type
BF16
Β·
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Model tree for ZhengPeng7/BiRefNet-V2-DIS5K

Finetuned
(17)
this model

Space using ZhengPeng7/BiRefNet-V2-DIS5K 1

Collection including ZhengPeng7/BiRefNet-V2-DIS5K

Papers for ZhengPeng7/BiRefNet-V2-DIS5K

Evaluation results