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.
1MEAN = np.array([0.485,0.456,0.406], np.float32)2STD = np.array([0.229,0.224,0.225], np.float32)3import numpy as np
4from PIL import Image
5from ai_edge_litert.interpreter import Interpreter
67# labels: https://raw.githubusercontent.com/CSAILVision/places365/master/categories_places365.txt8labels =[l.split(" ")[0][3:]for l inopen("categories_places365.txt")]910img = Image.open("scene.jpg").convert("RGB").resize((224,224))11x =((np.asarray(img, np.float32)/255- MEAN)/ STD).transpose(2,0,1)[None]1213it = Interpreter(model_path="places_fp16.tflite"); it.allocate_tensors()14it.set_tensor(it.get_input_details()[0]["index"], x); it.invoke()15z = it.get_tensor(it.get_output_details()[0]["index"])[0]# [365]16p = np.exp(z - z.max()); p /= p.sum()17for i in p.argsort()[-5:][::-1]:18print(f"{labels[i]}: {p[i]:.3f}")
How it converts (litert-torch) — two numerically-exact re-authorings
global AdaptiveAvgPool2d(1) → mean(3).mean(2) (multi-axis-pool fix).
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.
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.
Runtime
Backend
Graph on GPU
Latency
LiteRT CompiledModel (LITERT_CL)
GPU
61 / 61
~2 ms
TFLite benchmark_model (TfLiteGpuDelegateV2)
GPU (OpenCL)
61 / 61
12.5 ms
TFLite benchmark_model
CPU (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).
backend
compiled
inference (median / min)
load
NPU (Hexagon v81)
on-device JIT
0.918 ms / 0.900 ms
104 ms
GPU (Adreno)
—
3.49 ms / 3.16 ms
507 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.
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).