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).

Downloads last month
-
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support