Image Segmentation
LiteRT
LiteRT
android
on-device
gpu
clothing-segmentation
fashion
virtual-try-on
u2net
Run this model with HF Jobs
Run litert-community/Cloth-Segmentation-U2Net-LiteRT on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/litert-community/Cloth-Segmentation-U2Net-LiteRT. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/litert-community/Cloth-Segmentation-U2Net-LiteRT on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use litert-community/Cloth-Segmentation-U2Net-LiteRT with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- LiteRT
How to use litert-community/Cloth-Segmentation-U2Net-LiteRT with LiteRT:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Notebooks
- Google Colab
- Kaggle
Upload README.md with huggingface_hub
Browse files12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182---license: mitlibrary_name: litertpipeline_tag: image-segmentationtags: - litert - tflite - android - on-device - gpu - clothing-segmentation - fashion - virtual-try-on - u2net---
# Cloth Segmentation (U²-Net) — LiteRT GPU
On-device **clothing segmentation** running **fully on the LiteRT `CompiledModel` GPU**delegate (no CPU fallback). [cloth-segmentation](https://github.com/levindabhi/cloth-segmentation)is a U²-Net trained on iMaterialist-Fashion to segment **upper-body / lower-body /full-body clothing** — the building block for virtual try-on and fashion apps. ~88 ms/frameon a Pixel 8a.
- **Architecture:** U²-Net (RSU nested residual blocks), 4-class head — pure CNN.- **Weights:** [levindabhi/cloth-segmentation](https://github.com/levindabhi/cloth-segmentation) (iMaterialist-Fashion) · MIT.- **Size:** 176 MB.

*Upper-body clothing (cyan) + lower-body (orange). Photo: Unsplash (free license).*
## I/O
- **Input:** `[1, 3, 768, 768]` NCHW, RGB, `(x/255 - 0.5)/0.5` (i.e. [-1, 1]).- **Output:** `[1, 4, 768, 768]` logits — `argmax` over the 4 classes: 0 = background, 1 = upper body, 2 = lower body, 3 = full body (dress).
## GPU conversion
U²-Net is a pure CNN → fully GPU-compatible (**254/254 nodes on the delegate, 1partition**; device corr 0.999798, ~88 ms) with **one defensive patch**: `align_corners=True`→ `False` on the bilinear upsamples (the GPU delegate rejects `align_corners=True`).CPU-exact vs PyTorch (corr 1.0).
## Minimal usage
### Kotlin (Android, LiteRT CompiledModel GPU)
```kotlinval options = CompiledModel.Options(Accelerator.GPU)val model = CompiledModel.create(context.assets, "clothseg.tflite", options, null)val inBufs = model.createInputBuffers()val outBufs = model.createOutputBuffers()
inBufs[0].writeFloat(inputNCHW) // [1,3,768,768] RGB, (x/255-0.5)/0.5model.run(inBufs, outBufs)val out = outBufs[0].readFloat() // [4*768*768]; per pixel p argmax over the 4 class planes// class 0 bg, 1 upper, 2 lower, 3 full-body```
### Python (LiteRT / ai-edge-litert)
```pythonimport numpy as npfrom ai_edge_litert.interpreter import Interpreter
it = Interpreter(model_path="clothseg.tflite"); it.allocate_tensors()inp, out = it.get_input_details(), it.get_output_details()it.set_tensor(inp[0]["index"], x) # [1,3,768,768] float32, RGB, (x/255-0.5)/0.5it.invoke()seg = it.get_tensor(out[0]["index"])[0].argmax(0) # [768,768] 0=bg 1=upper 2=lower 3=full```
## Conversion
Converted with **litert-torch** (`build_clothseg.py`): loads the MIT U²-Net cloth weightsand exports the 4-class graph.
## License
MIT (cloth-segmentation / levindabhi). Trained on iMaterialist-Fashion-2019.README.mdAdded+82