snnn001 commited on
Commit
01e4745
·
verified ·
1 Parent(s): 06d1e9a

Add model

Browse files
Files changed (4) hide show
  1. BiRefNet-Lite-fp32.tflite +3 -0
  2. LICENSE +21 -0
  3. README.md +85 -0
  4. SHA256SUMS +1 -0
BiRefNet-Lite-fp32.tflite ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ddfafe4f881ea08dca4bef19391136989a21a53aea12fc639d275fd4c643677d
3
+ size 184001424
LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2024 ZhengPeng
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
README.md ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ library_name: litert
4
+ pipeline_tag: image-segmentation
5
+ base_model: ZhengPeng7/BiRefNet_lite
6
+ tags:
7
+ - litert
8
+ - tflite
9
+ - fp32
10
+ - background-removal
11
+ - foreground-segmentation
12
+ - birefnet
13
+ ---
14
+
15
+ # BiRefNet-Lite for LiteRT
16
+
17
+ FP32 LiteRT/TFLite export of BiRefNet Lite for foreground segmentation and background removal. The model returns a soft foreground mask with the final sigmoid included.
18
+
19
+ Source checkpoint: [ZhengPeng7/BiRefNet_lite](https://huggingface.co/ZhengPeng7/BiRefNet_lite), revision [`aa62cd87eafb9cc43056d08ef3615a14628b831d`](https://huggingface.co/ZhengPeng7/BiRefNet_lite/tree/aa62cd87eafb9cc43056d08ef3615a14628b831d).
20
+
21
+ ## Model file
22
+
23
+ [BiRefNet-Lite-fp32.tflite](BiRefNet-Lite-fp32.tflite) · FP32 · 184.00 MB. The file hash is in [SHA256SUMS](SHA256SUMS).
24
+
25
+ The TFLite signature is `main`. All input and output tensors are `float32`; shapes are fixed. Image/video decoding, preprocessing, and application postprocessing run on the host.
26
+
27
+ | Direction | Name | Shape | Meaning |
28
+ | --- | --- | --- | --- |
29
+ | Input | `pixel_values` | `[1, 3, 1024, 1024]` | Normalized RGB, NCHW |
30
+ | Output | `foreground_probability` | `[1, 1, 1024, 1024]` | Foreground probability in [0, 1], NCHW |
31
+
32
+ ## Preprocessing and outputs
33
+
34
+ Convert the image to RGB, resize to **1024 × 1024** with PIL bilinear interpolation, divide by 255, and normalize with ImageNet mean `[0.485, 0.456, 0.406]` and standard deviation `[0.229, 0.224, 0.225]`. Transpose to NCHW. Resize the output probability map to the original image size for an alpha mask.
35
+
36
+ ## Run on CPU
37
+
38
+ ```bash
39
+ pip install ai-edge-litert huggingface_hub numpy pillow
40
+ ```
41
+
42
+ ```python
43
+ import numpy as np
44
+ from huggingface_hub import hf_hub_download
45
+ from ai_edge_litert.interpreter import Interpreter
46
+ from PIL import Image
47
+
48
+ image = Image.open("image.jpg").convert("RGB")
49
+ rgb = np.asarray(image.resize((1024, 1024), Image.Resampling.BILINEAR),
50
+ dtype=np.float32) / 255.0
51
+ mean = np.array([0.485, 0.456, 0.406], dtype=np.float32)
52
+ std = np.array([0.229, 0.224, 0.225], dtype=np.float32)
53
+ pixel_values = np.ascontiguousarray(((rgb - mean) / std).transpose(2, 0, 1)[None])
54
+
55
+ model_path = hf_hub_download("litert-community/BiRefNet-Lite", "BiRefNet-Lite-fp32.tflite")
56
+ interpreter = Interpreter(model_path=model_path, num_threads=4)
57
+ interpreter.allocate_tensors()
58
+ run = interpreter.get_signature_runner("main")
59
+ probability = run(pixel_values=pixel_values)["foreground_probability"][0, 0]
60
+ # Restore the soft foreground mask to the original image dimensions.
61
+ mask = Image.fromarray(probability).resize(image.size, Image.Resampling.BILINEAR)
62
+ alpha = Image.fromarray(np.rint(np.clip(np.asarray(mask), 0, 1) * 255).astype(np.uint8))
63
+ rgba = image.convert("RGBA")
64
+ rgba.putalpha(alpha)
65
+ rgba.save("foreground.png")
66
+ ```
67
+
68
+ ## Source and license
69
+
70
+ BiRefNet is by Peng Zheng and collaborators. See the [project](https://github.com/ZhengPeng7/BiRefNet) and [paper](https://arxiv.org/abs/2401.03407).
71
+
72
+ This FP32 conversion uses the original pretrained weights with a fixed-shape TFLite interface. License: [MIT](LICENSE).
73
+
74
+ ## Citation
75
+
76
+ ```bibtex
77
+ @article{zheng2024birefnet,
78
+ title={Bilateral Reference for High-Resolution Dichotomous Image Segmentation},
79
+ author={Zheng, Peng and Gao, Dehong and Fan, Deng-Ping and Liu, Li and Laaksonen, Jorma and Ouyang, Wanli and Sebe, Nicu},
80
+ journal={CAAI Artificial Intelligence Research},
81
+ volume={3},
82
+ pages={9150038},
83
+ year={2024}
84
+ }
85
+ ```
SHA256SUMS ADDED
@@ -0,0 +1 @@
 
 
1
+ ddfafe4f881ea08dca4bef19391136989a21a53aea12fc639d275fd4c643677d BiRefNet-Lite-fp32.tflite