# Option 1: use with transformers
from transformers import AutoModelForImageSegmentation
birefnet = AutoModelForImageSegmentation.from_pretrained("ezzdev/BiRefNet", trust_remote_code=True)
# Option 2: use with BiRefNet
# Install from https://github.com/ZhengPeng7/BiRefNet
from models.birefnet import BiRefNet
model = BiRefNet.from_pretrained("ezzdev/BiRefNet")
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("image-segmentation", model="ezzdev/BiRefNet", trust_remote_code=True)
# Load model directly
from transformers import AutoModelForImageSegmentation
model = AutoModelForImageSegmentation.from_pretrained("ezzdev/BiRefNet", trust_remote_code=True, dtype="auto")
1 Nankai University 2 Northwestern Polytechnical University 3 National University of Defense Technology 4 Aalto University 5 Shanghai AI Laboratory 6 University of Trento
Only use the weights on HuggingFace -- Pro: No need to download BiRefNet codes manually; Con: Codes on HuggingFace might not be latest version (I'll try to keep them always latest).
Online Inference with GUI on Hugging Face with adjustable resolutions:
Inference and evaluation of your given weights:
Acknowledgement:
Many thanks to @Freepik for their generous support on GPU resources for training higher resolution BiRefNet models and more of my explorations.
Many thanks to @fal for their generous support on GPU resources for training better general BiRefNet models.
Many thanks to @not-lain for his help on the better deployment of our BiRefNet model on HuggingFace.
Citation
@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}
}