Run this model with HF Jobs
Run ZhengPeng7/BiRefNet-V2-COD 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-COD. 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-COD 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.
Instructions to use ZhengPeng7/BiRefNet-V2-COD with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ZhengPeng7/BiRefNet-V2-COD with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-segmentation", model="ZhengPeng7/BiRefNet-V2-COD", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForImageSegmentation model = AutoModelForImageSegmentation.from_pretrained("ZhengPeng7/BiRefNet-V2-COD", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
BiRefNet-V2-COD
BiRefNet-V2 with a DINOv3-L backbone for camouflaged object detection (COD), trained on COD10K-TR, CAMO-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 cod--epoch_12). Higher is better except for MAE.
| Test set | S-measure | weighted F | mean F | mean E | max E | MAE |
|---|---|---|---|---|---|---|
TE-CAMO |
.925 | .909 | .916 | .963 | .971 | .024 |
TE-COD10K |
.934 | .901 | .906 | .970 | .978 | .012 |
NC4K |
.928 | .908 | .918 | .959 | .967 | .020 |
CHAMELEON |
.938 | .913 | .918 | .970 | .980 | .016 |
CHAMELEON is not reported in the paper.
The test sets:
| Test set | Images | Description | Paper | License of the data |
|---|---|---|---|---|
TE-CAMO |
250 | Test set of CAMO, naturally and artificially camouflaged objects (usually animals and humans). | CVIU 2019 | CC BY-NC-SA 4.0 |
TE-COD10K |
2,026 | Camouflaged images of the test set of COD10K, which covers camouflaged objects in natural scenes over 78 object categories. | CVPR 2020 | Non-commercial purposes only |
NC4K |
4,121 | Test set of camouflaged objects, images downloaded from the Internet. | CVPR 2021 | Not stated |
CHAMELEON |
76 | Photos of camouflaged animals taken from the Internet, manually annotated. | Unpublished manuscript | Not stated |
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 COD10K-TR, CAMO-TR for 30 epochs, the schedule of scripts/train.sh of the code repository for this task; these are the weights saved at epoch 12. The training sets, 4,040 images in total:
| Training set | Images | Description | Paper | License of the data |
|---|---|---|---|---|
| COD10K-TR | 3,040 | Camouflaged images of the training set of COD10K, which covers camouflaged objects in natural scenes over 78 object categories. | CVPR 2020 | Non-commercial purposes only |
| CAMO-TR | 1,000 | Training set of CAMO, naturally and artificially camouflaged objects (usually animals and humans). | CVIU 2019 | CC BY-NC-SA 4.0 |
How to use
from transformers import AutoModelForImageSegmentation
model = AutoModelForImageSegmentation.from_pretrained('ZhengPeng7/BiRefNet-V2-COD', 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-COD', 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-COD-epoch_12.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
- -
Model tree for ZhengPeng7/BiRefNet-V2-COD
Base model
timm/vit_large_patch16_dinov3.lvd1689mSpace using ZhengPeng7/BiRefNet-V2-COD 1
Collection including ZhengPeng7/BiRefNet-V2-COD
Papers for ZhengPeng7/BiRefNet-V2-COD
BiRefNet-V2: Rethinking Bilateral Reference for High-Resolution Dichotomous Image Segmentation
Anabranch Network for Camouflaged Object Segmentation
Simultaneously Localize, Segment and Rank the Camouflaged Objects
Evaluation results
- S-measure on TE-CAMOself-reported0.925
- weighted F on TE-CAMOself-reported0.909
- mean F on TE-CAMOself-reported0.916
- mean E on TE-CAMOself-reported0.963
- max E on TE-CAMOself-reported0.971
- MAE on TE-CAMOself-reported0.024
- S-measure on TE-COD10Kself-reported0.934
- weighted F on TE-COD10Kself-reported0.901