Xenova HF staff commited on
Commit
4779e87
·
verified ·
1 Parent(s): d34a6bc

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +83 -0
README.md ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: transformers.js
3
+ tags:
4
+ - background-removal
5
+ - mask-generation
6
+ - Dichotomous Image Segmentation
7
+ - Camouflaged Object Detection
8
+ - Salient Object Detection
9
+ repo_url: https://github.com/ZhengPeng7/BiRefNet
10
+ pipeline_tag: image-segmentation
11
+ ---
12
+ <h1 align="center">Bilateral Reference for High-Resolution Dichotomous Image Segmentation</h1>
13
+
14
+ <div align='center'>
15
+ <a href='https://scholar.google.com/citations?user=TZRzWOsAAAAJ' target='_blank'><strong>Peng Zheng</strong></a><sup> 1,4,5,6</sup>,&thinsp;
16
+ <a href='https://scholar.google.com/citations?user=0uPb8MMAAAAJ' target='_blank'><strong>Dehong Gao</strong></a><sup> 2</sup>,&thinsp;
17
+ <a href='https://scholar.google.com/citations?user=kakwJ5QAAAAJ' target='_blank'><strong>Deng-Ping Fan</strong></a><sup> 1*</sup>,&thinsp;
18
+ <a href='https://scholar.google.com/citations?user=9cMQrVsAAAAJ' target='_blank'><strong>Li Liu</strong></a><sup> 3</sup>,&thinsp;
19
+ <a href='https://scholar.google.com/citations?user=qQP6WXIAAAAJ' target='_blank'><strong>Jorma Laaksonen</strong></a><sup> 4</sup>,&thinsp;
20
+ <a href='https://scholar.google.com/citations?user=pw_0Z_UAAAAJ' target='_blank'><strong>Wanli Ouyang</strong></a><sup> 5</sup>,&thinsp;
21
+ <a href='https://scholar.google.com/citations?user=stFCYOAAAAAJ' target='_blank'><strong>Nicu Sebe</strong></a><sup> 6</sup>
22
+ </div>
23
+
24
+ <div align='center'>
25
+ <sup>1 </sup>Nankai University&ensp; <sup>2 </sup>Northwestern Polytechnical University&ensp; <sup>3 </sup>National University of Defense Technology&ensp; <sup>4 </sup>Aalto University&ensp; <sup>5 </sup>Shanghai AI Laboratory&ensp; <sup>6 </sup>University of Trento&ensp;
26
+ </div>
27
+
28
+ | *DIS-Sample_1* | *DIS-Sample_2* |
29
+ | :------------------------------: | :-------------------------------: |
30
+ | <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" /> |
31
+
32
+ For more information, check out the official [repository](https://github.com/ZhengPeng7/BiRefNet).
33
+
34
+ ## Usage (Transformers.js)
35
+
36
+ If you haven't already, you can install the [Transformers.js](https://huggingface.co/docs/transformers.js) JavaScript library from [NPM](https://www.npmjs.com/package/@xenova/transformers) using:
37
+ ```bash
38
+ npm i @huggingface/transformers
39
+ ```
40
+
41
+ You can then use the model for image matting, as follows:
42
+
43
+ ```js
44
+ import { AutoModel, AutoProcessor, RawImage } from '@huggingface/transformers';
45
+
46
+ // Load model and processor
47
+ const model_id = 'onnx-community/BiRefNet_T';
48
+ const model = await AutoModel.from_pretrained(model_id, { dtype: 'fp32' });
49
+ const processor = await AutoProcessor.from_pretrained(model_id);
50
+
51
+ // Load image from URL
52
+ const url = 'https://images.pexels.com/photos/5965592/pexels-photo-5965592.jpeg?auto=compress&cs=tinysrgb&w=1024';
53
+ const image = await RawImage.fromURL(url);
54
+
55
+ // Pre-process image
56
+ const { pixel_values } = await processor(image);
57
+
58
+ // Predict alpha matte
59
+ const { output_image } = await model({ input_image: pixel_values });
60
+
61
+ // Save output mask
62
+ const mask = await RawImage.fromTensor(output_image[0].sigmoid().mul(255).to('uint8')).resize(image.width, image.height);
63
+ mask.save('mask.png');
64
+ ```
65
+
66
+ | Input image | Output mask |
67
+ |--------|--------|
68
+ | ![image/png](https://cdn-uploads.huggingface.co/production/uploads/61b253b7ac5ecaae3d1efe0c/cRw4xmlhgkCZ72qJckrps.png) | ![image/png](https://cdn-uploads.huggingface.co/production/uploads/61b253b7ac5ecaae3d1efe0c/pcUeTxkZKPRVfT5oDn0Un.png) |
69
+
70
+ ## Citation
71
+
72
+ ```
73
+ @article{BiRefNet,
74
+ title={Bilateral Reference for High-Resolution Dichotomous Image Segmentation},
75
+ author={Zheng, Peng and Gao, Dehong and Fan, Deng-Ping and Liu, Li and Laaksonen, Jorma and Ouyang, Wanli and Sebe, Nicu},
76
+ journal={CAAI Artificial Intelligence Research},
77
+ year={2024}
78
+ }
79
+ ```
80
+
81
+ ---
82
+
83
+ 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](https://huggingface.co/docs/optimum/index) and structuring your repo like this one (with ONNX weights located in a subfolder named `onnx`).