mlboydaisuke commited on
Commit
f2549f0
·
verified ·
1 Parent(s): e0961b9

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +82 -0
README.md ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ library_name: litert
4
+ pipeline_tag: image-segmentation
5
+ tags:
6
+ - litert
7
+ - tflite
8
+ - android
9
+ - on-device
10
+ - gpu
11
+ - clothing-segmentation
12
+ - fashion
13
+ - virtual-try-on
14
+ - u2net
15
+ ---
16
+
17
+ # Cloth Segmentation (U²-Net) — LiteRT GPU
18
+
19
+ On-device **clothing segmentation** running **fully on the LiteRT `CompiledModel` GPU**
20
+ delegate (no CPU fallback). [cloth-segmentation](https://github.com/levindabhi/cloth-segmentation)
21
+ is a U²-Net trained on iMaterialist-Fashion to segment **upper-body / lower-body /
22
+ full-body clothing** — the building block for virtual try-on and fashion apps. ~88 ms/frame
23
+ on a Pixel 8a.
24
+
25
+ - **Architecture:** U²-Net (RSU nested residual blocks), 4-class head — pure CNN.
26
+ - **Weights:** [levindabhi/cloth-segmentation](https://github.com/levindabhi/cloth-segmentation) (iMaterialist-Fashion) · MIT.
27
+ - **Size:** 176 MB.
28
+
29
+ ![Cloth segmentation](hero.png)
30
+
31
+ *Upper-body clothing (cyan) + lower-body (orange). Photo: Unsplash (free license).*
32
+
33
+ ## I/O
34
+
35
+ - **Input:** `[1, 3, 768, 768]` NCHW, RGB, `(x/255 - 0.5)/0.5` (i.e. [-1, 1]).
36
+ - **Output:** `[1, 4, 768, 768]` logits — `argmax` over the 4 classes: 0 = background,
37
+ 1 = upper body, 2 = lower body, 3 = full body (dress).
38
+
39
+ ## GPU conversion
40
+
41
+ U²-Net is a pure CNN → fully GPU-compatible (**254/254 nodes on the delegate, 1
42
+ partition**; device corr 0.999798, ~88 ms) with **one defensive patch**: `align_corners=True`
43
+ → `False` on the bilinear upsamples (the GPU delegate rejects `align_corners=True`).
44
+ CPU-exact vs PyTorch (corr 1.0).
45
+
46
+ ## Minimal usage
47
+
48
+ ### Kotlin (Android, LiteRT CompiledModel GPU)
49
+
50
+ ```kotlin
51
+ val options = CompiledModel.Options(Accelerator.GPU)
52
+ val model = CompiledModel.create(context.assets, "clothseg.tflite", options, null)
53
+ val inBufs = model.createInputBuffers()
54
+ val outBufs = model.createOutputBuffers()
55
+
56
+ inBufs[0].writeFloat(inputNCHW) // [1,3,768,768] RGB, (x/255-0.5)/0.5
57
+ model.run(inBufs, outBufs)
58
+ val out = outBufs[0].readFloat() // [4*768*768]; per pixel p argmax over the 4 class planes
59
+ // class 0 bg, 1 upper, 2 lower, 3 full-body
60
+ ```
61
+
62
+ ### Python (LiteRT / ai-edge-litert)
63
+
64
+ ```python
65
+ import numpy as np
66
+ from ai_edge_litert.interpreter import Interpreter
67
+
68
+ it = Interpreter(model_path="clothseg.tflite"); it.allocate_tensors()
69
+ inp, out = it.get_input_details(), it.get_output_details()
70
+ it.set_tensor(inp[0]["index"], x) # [1,3,768,768] float32, RGB, (x/255-0.5)/0.5
71
+ it.invoke()
72
+ seg = it.get_tensor(out[0]["index"])[0].argmax(0) # [768,768] 0=bg 1=upper 2=lower 3=full
73
+ ```
74
+
75
+ ## Conversion
76
+
77
+ Converted with **litert-torch** (`build_clothseg.py`): loads the MIT U²-Net cloth weights
78
+ and exports the 4-class graph.
79
+
80
+ ## License
81
+
82
+ MIT (cloth-segmentation / levindabhi). Trained on iMaterialist-Fashion-2019.