CoolFace
Modelpublic

litert-community/Places365-ResNet18-LiteRT

sourceHugging Facemitupdated 15d agoView on Hugging Face
0likes266downloads
Model Card

Measured on device (edge-compat): Galaxy S26 · LiteRT 2.2.0 · GPU (ML Drift) · 3.49 ms p50 (2026-08-26); Galaxy S26 · LiteRT 2.2.0 · NPU (QNN/HTP) · 0.92 ms p50 (2026-08-26); Raspberry Pi 5 · LiteRT 2.2.0.dev20260804 · CPU/XNNPACK, 4 threads · 34.0 ms p50 (2026-08-31); browser · Chromium 151 on M4 Max · LiteRT.js 2.5.3 · WebGPU · 2.72 ms p50 · output matches CPU (2026-08-11). Record: https://github.com/john-rocky/edge-compat/blob/main/cards/places365-resnet18/CARD.md

Places365 ResNet18 — LiteRT (on-device scene recognition, fully-GPU)

ResNet18 trained on Places365 (CSAILVision), converted to LiteRT and running fully on the `CompiledModel` GPU (ML Drift) on Android. Scene/place recognition across 365 categories (beach, kitchen, forest, office, restaurant, …) — a distinct task from object classification.

[image]

On-device (Pixel 8a, Tensor G3 — verified)

nodes on GPU61 / 61 LITERT_CL (full residency)
inference~2 ms (224×224)
size22.8 MB (fp16)
accuracydevice-vs-PyTorch corr 1.0, top-1 match
image[1,3,224,224] (ImageNet-normalized) →[GPU: ResNet18]→ logits[1,365]

Minimal usage

Android (Kotlin, CompiledModel GPU)

kotlin
val model = CompiledModel.create(context.assets, "places_fp16.tflite",
    CompiledModel.Options(Accelerator.GPU), null)
val inputs = model.createInputBuffers()
val outputs = model.createOutputBuffers()
inputs[0].writeFloat(chw)            // [1,3,224,224] ImageNet-normalized, NCHW
model.run(inputs, outputs)
val logits = outputs[0].readFloat()    // [1,365] scene logits -> softmax top-k

Python (desktop verification)

python
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

# labels: https://raw.githubusercontent.com/CSAILVision/places365/master/categories_places365.txt
labels = [l.split(" ")[0][3:] for l in open("categories_places365.txt")]

img = Image.open("scene.jpg").convert("RGB").resize((224, 224))
x = ((np.asarray(img, np.float32) / 255 - MEAN) / STD).transpose(2, 0, 1)[None]

it = Interpreter(model_path="places_fp16.tflite"); it.allocate_tensors()
it.set_tensor(it.get_input_details()[0]["index"], x); it.invoke()
z = it.get_tensor(it.get_output_details()[0]["index"])[0]        # [365]
p = np.exp(z - z.max()); p /= p.sum()
for i in p.argsort()[-5:][::-1]:
    print(f"{labels[i]}: {p[i]:.3f}")

How it converts (litert-torch) — two numerically-exact re-authorings

  1. 1.global AdaptiveAvgPool2d(1)mean(3).mean(2) (multi-axis-pool fix).
  2. 2.ResNet stem `MaxPool2d(3,s2,p1)` → zero-pad + valid max-pool. PyTorch's max-pool pads with -inf → a PADV2 op the Mali delegate won't delegate (splits the graph → compile fail). Since the pool follows a ReLU (inputs ≥ 0), a 0-pad is exactly equivalent and emits a delegatable PAD → full GPU residency.

Result: banned ops NONE, all tensors ≤4D, tflite-vs-torch corr 1.0, device-vs-torch corr 1.0.

Preprocessing

Center-crop to square, resize to 224×224, /255, ImageNet mean/std, NCHW. Output 365-class scene logits; softmax + argmax for top-k.

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.

RuntimeBackendGraph on GPULatency
LiteRT CompiledModel (LITERT_CL)GPU61 / 61~2 ms
TFLite benchmark_model (TfLiteGpuDelegateV2)GPU (OpenCL)61 / 6112.5 ms
TFLite benchmark_modelCPU (XNNPACK, 4 threads)62.0 ms

The two GPU rows are different runtimes, not a contradiction. The LITERT_CL figure is the one recorded when this model shipped, taken through LiteRT's own CompiledModel accelerator — the path the Kotlin sample app and the LiteRT API use. The TfLiteGpuDelegateV2 figure is the classic TFLite OpenCL delegate, measured with a tool anyone can download and re-run. They agree on how much of the graph the GPU takes; they disagree on speed, and the classic delegate is the slower of the two here. Read the TfLiteGpuDelegateV2 row as a reproducible floor, not as this model's speed on LiteRT.

Snapdragon NPU (Hexagon)

The NPU is 3.80x faster than the GPU (0.918 ms against 3.49 ms) and loads 4.86x faster (104 ms against 507 ms).

backendcompiledinference (median / min)load
NPU (Hexagon v81)on-device JIT0.918 ms / 0.900 ms104 ms
GPU (Adreno)3.49 ms / 3.16 ms507 ms

Measured on a Samsung Galaxy S26 (Snapdragon 8 Elite Gen 5 / SM8850, Hexagon v81, Android 16) with 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.80, where 1.0 is the throttling threshold.

The NPU rows ran the published file unchanged. LiteRT compiled it for the Hexagon on the device at first load. That first compile took 508 ms here. The load column above is the cached load every later run pays. Recipe and the runtime libraries it needs: NPU guide.

GPU wiring: GPU guide.

Raspberry Pi 5 (CPU)

Measured on a Raspberry Pi 5 Model B Rev 1.1 (8 GB, Raspberry Pi OS 64-bit) with the LiteRT `benchmark_model` tool from litert-cli-nightly 0.2.0.dev20260805: CPU inference (XNNPACK, 4 threads), 3 invocations per file of 10 warm-up plus 50 timed runs (the tool caps a phase at 150 s, so very slow graphs run fewer — the Runs column is the actual timed total). The latency is the median across invocations; the spread is the min–max over all timed runs. No thermal throttling occurred during these runs (vcgencmd get_throttled stayed 0x0).

FileInference (median)Spread (min–max)RunsPeak memory
places_fp16.tflite34.0 ms33.8–34.9 ms150138 MB

License

MIT. Upstream: CSAILVision/places365.