mlboydaisuke commited on
Commit
bf5233d
·
verified ·
1 Parent(s): 2387ef8

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. README.md +76 -0
  2. u2net_fp16.tflite +3 -0
README.md ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ library_name: litert
4
+ pipeline_tag: image-segmentation
5
+ base_model: xuebinqin/U-2-Net
6
+ tags:
7
+ - litert
8
+ - tflite
9
+ - on-device
10
+ - android
11
+ - background-removal
12
+ - salient-object-detection
13
+ - image-matting
14
+ - u2net
15
+ ---
16
+
17
+ # U²-Net — LiteRT (TFLite) GPU, FP16
18
+
19
+ On-device [LiteRT](https://ai.google.dev/edge/litert) (`.tflite`) conversion of
20
+ **[U²-Net](https://github.com/xuebinqin/U-2-Net)** for salient-object segmentation /
21
+ **background removal**. U²-Net is a nested U-structure ("U-net of U-nets", a pure CNN)
22
+ that predicts a single-channel saliency mask; the foreground is composited onto
23
+ transparency to cut the subject out of its background.
24
+
25
+ The model runs **fully on the LiteRT `CompiledModel` GPU accelerator** (ML Drift):
26
+ every op is GPU-native, no CPU fallback, no Flex ops. It converts with
27
+ [`litert-torch`](https://github.com/google-ai-edge/ai-edge-torch) **with no custom
28
+ rewrites** (pure CNN).
29
+
30
+ ## Files
31
+
32
+ | File | Size | Description |
33
+ |------|------|-------------|
34
+ | `u2net_fp16.tflite` | 88 MB | float16 weights, GPU-compatible |
35
+
36
+ ## I/O
37
+
38
+ - **Input**: `[1, 3, 320, 320]` float32, **NCHW**, RGB. Preprocessing: resize to 320×320,
39
+ divide by the per-image max, then ImageNet normalize
40
+ (`mean = [0.485, 0.456, 0.406]`, `std = [0.229, 0.224, 0.225]`).
41
+ - **Output**: `[1, 1, 320, 320]` saliency mask in `[0, 1]` (sigmoid). Upscale to the input
42
+ size and use as the foreground alpha.
43
+
44
+ ## Usage (Android, LiteRT CompiledModel)
45
+
46
+ ```kotlin
47
+ val model = CompiledModel.create(
48
+ context.assets, "u2net_fp16.tflite",
49
+ CompiledModel.Options(Accelerator.GPU), null
50
+ )
51
+ val inputs = model.createInputBuffers()
52
+ val outputs = model.createOutputBuffers()
53
+ inputs[0].writeFloat(nchwFloatArray) // [1,3,320,320]
54
+ model.run(inputs, outputs)
55
+ val mask = outputs[0].readFloat() // [1,1,320,320] in [0,1]
56
+ ```
57
+
58
+ A complete Android sample (live camera + gallery background removal) is available in
59
+ [google-ai-edge/litert-samples](https://github.com/google-ai-edge/litert-samples).
60
+
61
+ ## Performance
62
+
63
+ - ~147 ms / frame on a Pixel 8a (Tensor G3, Mali) GPU.
64
+
65
+ ## Conversion notes
66
+
67
+ Converted with `litert-torch` (full U2NET, 44M params) and float16-quantized with
68
+ `ai-edge-quantizer`. Verified: all ops GPU-native, output correlation = 1.0 vs the PyTorch
69
+ reference (FP32), ~0.9999 for the FP16 build.
70
+
71
+ ## License & attribution
72
+
73
+ - License: **Apache-2.0** (© the U²-Net authors,
74
+ [xuebinqin/U-2-Net](https://github.com/xuebinqin/U-2-Net/blob/master/LICENSE)).
75
+ - This is a format conversion of the official U²-Net weights (no architectural changes);
76
+ all credit to the original authors.
u2net_fp16.tflite ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:dd338f190a538ca3de9792b20b7617038cd56f8e440f38ff25da5554f32b9df2
3
+ size 88230272