Instructions to use litert-community/NIMA-LiteRT with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- LiteRT
How to use litert-community/NIMA-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
NIMA β LiteRT on-device image quality assessment
NIMA (Neural Image Assessment) (idealo, Apache-2.0) re-authored for LiteRT: score a photo's quality on a 1-10 scale. Two MobileNet models β aesthetic (AVA) and technical (TID2013) β each predict a 10-bin score distribution; the score is the distribution mean. Both run fully on the CompiledModel GPU (~6.4 MB each).
Verified on a Pixel 8a: ~173 ms for both models; tflite-vs-Keras score parity 0.999998 (aesthetic) / 0.999915 (technical).
Files
| file | in β out | delegate |
|---|---|---|
nima_aesthetic_fp16.tflite |
image [1,224,224,3] β dist [10] | GPU |
nima_technical_fp16.tflite |
image [1,224,224,3] β dist [10] | GPU |
image β[resize 224Β² Β· MobileNet /127.5β1]β [GPU MobileNet]β softmax dist[10] β[Ξ£ iΒ·pα΅’]β score 1-10
Minimal usage (Python)
import numpy as np
from PIL import Image
from ai_edge_litert.interpreter import Interpreter
img = Image.open("photo.jpg").convert("RGB").resize((224, 224))
x = (np.asarray(img, np.float32) / 127.5 - 1.0)[None] # NHWC, [-1,1]
def score(model):
it = Interpreter(model_path=model); it.allocate_tensors()
it.set_tensor(it.get_input_details()[0]["index"], x); it.invoke()
dist = it.get_tensor(it.get_output_details()[0]["index"])[0]
return float((np.arange(10) + 1) @ dist) # mean over 1..10
print("aesthetic", score("nima_aesthetic_fp16.tflite"))
print("technical", score("nima_technical_fp16.tflite"))
Minimal usage (Kotlin, LiteRT CompiledModel)
val m = CompiledModel.create(assets, "nima_aesthetic_fp16.tflite", CompiledModel.Options(Accelerator.GPU), null)
val inp = m.createInputBuffers(); val out = m.createOutputBuffers()
inp[0].writeFloat(preprocess(bitmap)) // resize 224Β², NHWC, v/127.5f - 1f
m.run(inp, out)
val dist = out[0].readFloat() // [10]
var score = 0f; for (i in 0 until 10) score += (i + 1) * dist[i] // 1-10
Upstream
idealo/image-quality-assessment (Apache-2.0) β NIMA MobileNet aesthetic + technical weights. Paper: NIMA: Neural Image Assessment (Talebi & Milanfar, 2018).
Performance
Measured on a Pixel 8a (Tensor G3, Android 16) with the standard TFLite benchmark_model tool β 10 warm-up runs then 50 timed runs, reported as the tool's mean.
| Runtime | Backend | Graph on GPU | Latency |
|---|---|---|---|
TFLite benchmark_model (TfLiteGpuDelegateV2) β nima_aesthetic_fp16.tflite |
GPU (OpenCL) | 86 / 86 | 11.3 ms |
TFLite benchmark_model (TfLiteGpuDelegateV2) β nima_technical_fp16.tflite |
GPU (OpenCL) | 86 / 86 | 10.9 ms |
TFLite benchmark_model β nima_aesthetic_fp16.tflite |
CPU (XNNPACK, 4 threads) | β | 18.5 ms |
TFLite benchmark_model β nima_technical_fp16.tflite |
CPU (XNNPACK, 4 threads) | β | 18.5 ms |
Any on-device figure recorded when this model shipped came from a different runtime. It was taken through LiteRT's own CompiledModel accelerator (logcat reports it as LITERT_CL), which is the path the Kotlin sample app and the LiteRT API use, and it appears elsewhere on this card. The rows above are the classic TFLite OpenCL delegate, measured with a tool anyone can download and re-run. The two are not comparable, so read the rows above as a reproducible floor rather than as this model's speed on LiteRT.
Snapdragon NPU (Hexagon)
nima_aesthetic_fp16.tfliteβ the NPU is 1.52x faster than the GPU (0.565 ms against 0.858 ms) and loads 3.61x faster (101 ms against 366 ms).nima_technical_fp16.tfliteβ the NPU is 1.54x faster than the GPU (0.554 ms against 0.854 ms) and loads 3.74x faster (99 ms against 371 ms).
| file | backend | inference (median / min) | load |
|---|---|---|---|
nima_aesthetic_fp16.tflite |
NPU (Hexagon v81) | 0.565 ms / 0.537 ms | 101 ms |
nima_aesthetic_fp16.tflite |
GPU (Adreno) | 0.858 ms / 0.724 ms | 366 ms |
nima_technical_fp16.tflite |
NPU (Hexagon v81) | 0.554 ms / 0.537 ms | 99 ms |
nima_technical_fp16.tflite |
GPU (Adreno) | 0.854 ms / 0.726 ms | 371 ms |
Measured on a Samsung Galaxy S26 (Snapdragon 8 Elite Gen 5 / SM8850, Hexagon v81, Android 16), LiteRT CompiledModel 2.2.0, one accelerator per process, 5 warm-up runs then N=50 timed runs, median reported. Every run held thermal status NONE throughout. Headroom 0.67-0.67, where 1.0 is the throttling threshold.
The NPU rows here ran artifacts compiled ahead of time for SM8850 with QAIRT 2.47.0; the GPU rows ran the published files as they are. LiteRT can also compile for the NPU on the device at first load, which is what lets you ship the published file unchanged β that path and the ten runtime libraries it needs are in the NPU recipe, and we did not measure it here. GPU wiring is in the GPU recipe.
- Downloads last month
- 167