onnx-community/BiRefNet-ONNX
<h1 align="center">Bilateral Reference for High-Resolution Dichotomous Image Segmentation</h1>
<div align='center'> <a href='https://scholar.google.com/citations?user=TZRzWOsAAAAJ' target='blank'><strong>Peng Zheng</strong></a><sup> 1,4,5,6</sup>,  <a href='https://scholar.google.com/citations?user=0uPb8MMAAAAJ' target='blank'><strong>Dehong Gao</strong></a><sup> 2</sup>,  <a href='https://scholar.google.com/citations?user=kakwJ5QAAAAJ' target='blank'><strong>Deng-Ping Fan</strong></a><sup> 1*</sup>,  <a href='https://scholar.google.com/citations?user=9cMQrVsAAAAJ' target='blank'><strong>Li Liu</strong></a><sup> 3</sup>,  <a href='https://scholar.google.com/citations?user=qQP6WXIAAAAJ' target='blank'><strong>Jorma Laaksonen</strong></a><sup> 4</sup>,  <a href='https://scholar.google.com/citations?user=pw0ZUAAAAJ' target='blank'><strong>Wanli Ouyang</strong></a><sup> 5</sup>,  <a href='https://scholar.google.com/citations?user=stFCYOAAAAAJ' target='_blank'><strong>Nicu Sebe</strong></a><sup> 6</sup> </div>
<div align='center'> <sup>1 </sup>Nankai University  <sup>2 </sup>Northwestern Polytechnical University  <sup>3 </sup>National University of Defense Technology  <sup>4 </sup>Aalto University  <sup>5 </sup>Shanghai AI Laboratory  <sup>6 </sup>University of Trento  </div>
For more information, check out the official repository.
Usage (Transformers.js)
If you haven't already, you can install the Transformers.js JavaScript library from NPM using:
npm i @huggingface/transformersYou can then use the model for image matting, as follows:
import { AutoModel, AutoProcessor, RawImage } from '@huggingface/transformers';
// Load model and processor
const model_id = 'onnx-community/BiRefNet-ONNX';
const model = await AutoModel.from_pretrained(model_id, { dtype: 'fp32' });
const processor = await AutoProcessor.from_pretrained(model_id);
// Load image from URL
const url = 'https://images.pexels.com/photos/5965592/pexels-photo-5965592.jpeg?auto=compress&cs=tinysrgb&w=1024';
const image = await RawImage.fromURL(url);
// Pre-process image
const { pixel_values } = await processor(image);
// Predict alpha matte
const { output_image } = await model({ input_image: pixel_values });
// Save output mask
const mask = await RawImage.fromTensor(output_image[0].sigmoid().mul(255).to('uint8')).resize(image.width, image.height);
mask.save('mask.png');Citation
@article{BiRefNet,
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},
year={2024}
}Note: Having a separate repo for ONNX weights is intended to be a temporary solution until WebML gains more traction. If you would like to make your models web-ready, we recommend converting to ONNX using 🤗 Optimum and structuring your repo like this one (with ONNX weights located in a subfolder named onnx).


