--- license: apache-2.0 library_name: litert pipeline_tag: image-classification tags: [nima, image-quality-assessment, aesthetic, technical, mobilenet, litert, tflite, on-device, gpu] base_model: idealo/image-quality-assessment --- # NIMA — LiteRT on-device image quality assessment [NIMA (Neural Image Assessment)](https://github.com/idealo/image-quality-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) ```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) ```kotlin 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](https://github.com/idealo/image-quality-assessment) (Apache-2.0) — NIMA MobileNet aesthetic + technical weights. Paper: *NIMA: Neural Image Assessment* (Talebi & Milanfar, 2018).