Downloads · 30 days
1.4K
25% of all-time downloads
onnx-community/BiRefNet-ONNX
BiRefNet-ONNX is a image segmentation model from onnx-community. Use it for the image segmentation task on the model card, and read the license before you ship it in a product. It is set up for transformers.js. The card lists the license as mit.
<h1 align="center"Bilateral Reference for High-Resolution Dichotomous Image Segmentation</h1
Downloads · 30 days
1.4K
25% of all-time downloads
All-time downloads
5.6K
Public
Repo size
1.5 GB
Likes
24
Public
Click a slice to open those files.
.onnx1.5 GB · 100%
From the Hugging Face model README
| DIS-Sample_1 | DIS-Sample_2 |
|---|---|
| <img src="https://drive.google.com/thumbnail?id=1ItXaA26iYnE8XQ_GgNLy71MOWePoS2-g&sz=w400" /> | <img src="https://drive.google.com/thumbnail?id=1Z-esCujQF_uEa_YJjkibc3NUrW4aR_d4&sz=w400" /> |
For more information, check out the official repository.
If you haven't already, you can install the Transformers.js JavaScript library from NPM using:
npm i @huggingface/transformers
You 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');
| Input image | Output mask |
|---|---|
![]() | ![]() |
@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).