Views
No views yet
| DIS-Sample_1 | DIS-Sample_2 |
|---|---|
npm i @huggingface/transformers1import { AutoModel, AutoProcessor, RawImage } from '@huggingface/transformers';
2
3// Load model and processor
4const model_id = 'onnx-community/BiRefNet-COD-ONNX';
5const model = await AutoModel.from_pretrained(model_id, { dtype: 'fp32' });
6const processor = await AutoProcessor.from_pretrained(model_id);
7
8// Load image from URL
9const url = 'https://images.pexels.com/photos/5965592/pexels-photo-5965592.jpeg?auto=compress&cs=tinysrgb&w=1024';
10const image = await RawImage.fromURL(url);
11
12// Pre-process image
13const { pixel_values } = await processor(image);
14
15// Predict alpha matte
16const { output_image } = await model({ input_image: pixel_values });
17
18// Save output mask
19const mask = await RawImage.fromTensor(output_image[0].sigmoid().mul(255).to('uint8')).resize(image.width, image.height);
20mask.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}
}onnx).