Image Segmentation
LiteRT
LiteRT
LiteRT
on-device
android
gpu
saliency
saliency-prediction
unisal
visual-attention
Instructions to use litert-community/UniSal-Saliency-LiteRT with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- LiteRT
How to use litert-community/UniSal-Saliency-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
UniSal β LiteRT (on-device visual saliency prediction, fully-GPU)
UniSal (rdroste), visual saliency prediction β a heatmap of where humans
look in an image β converted to LiteRT and running fully on the CompiledModel GPU (ML Drift) on
Android. MobileNetV2 encoder + bilinear decoder, 3.71 M params / 6.5 MB fp16.
On-device (Pixel 8a, Tensor G3 β verified)
| nodes on GPU | 158 / 158 LITERT_CL (full residency) |
| inference | ~3 ms (256Γ256) |
| size | 6.5 MB (fp16) |
| accuracy | device-vs-PyTorch corr 0.9998 |
image[1,3,256,256] (ImageNet mean/std) β[GPU: UniSal]β saliency[1,1,256,256] (higher = more attended)
Minimal usage
Android (Kotlin, CompiledModel GPU)
val model = CompiledModel.create(context.assets, "unisal_fp16.tflite",
CompiledModel.Options(Accelerator.GPU), null)
val inputs = model.createInputBuffers()
val outputs = model.createOutputBuffers()
inputs[0].writeFloat(chw) // [1,3,256,256] ImageNet-normalized, NCHW
model.run(inputs, outputs)
val sal = outputs[0].readFloat() // [1,1,256,256] saliency (higher = more attended)
Python (desktop verification)
MEAN = np.array([0.485, 0.456, 0.406], np.float32)
STD = np.array([0.229, 0.224, 0.225], np.float32)
import numpy as np
from PIL import Image
from ai_edge_litert.interpreter import Interpreter
img = Image.open("photo.jpg").convert("RGB").resize((256, 256))
x = ((np.asarray(img, np.float32) / 255 - MEAN) / STD).transpose(2, 0, 1)[None]
it = Interpreter(model_path="unisal_fp16.tflite"); it.allocate_tensors()
it.set_tensor(it.get_input_details()[0]["index"], x); it.invoke()
s = it.get_tensor(it.get_output_details()[0]["index"])[0, 0] # [256,256]
s = (s - s.min()) / (s.max() - s.min())
Image.fromarray((s * 255).astype(np.uint8)).save("saliency.png")
How it converts (litert-torch) β three numerically-exact fixes
- Strided subsample
x[..., ::2, ::2]βF.avg_pool2d(x, 1, 2)(same pixels; avoidsGATHER_ND). - Bake the 16 Gaussian prior maps (size-only constants; avoids
GATHER_ND/BROADCAST_TO). F.pad(replicate)β 0-pad for the 41Γ41 Gaussian smoothing (which is kept β it suppresses border artifacts, not cosmetic).
Result: banned ops NONE, β€4D, tflite-vs-torch corr 1.0, device-vs-torch corr 0.9998. Static-image path (Bypass-RNN + SALICON domain pinned); the spatial log-softmax / normalization runs in the app.
Preprocessing
Center-crop, resize 256Γ256, /255, ImageNet mean/std, NCHW.
License
Apache-2.0. Upstream: rdroste/unisal.
- Downloads last month
- 61
