Instructions to use litert-community/Places365-ResNet18-LiteRT with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- LiteRT
How to use litert-community/Places365-ResNet18-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
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.
On-device (Pixel 8a, Tensor G3 β verified)
| nodes on GPU | 61 / 61 LITERT_CL (full residency) |
| inference | ~2 ms (224Γ224) |
| size | 22.8 MB (fp16) |
| accuracy | device-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)
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)
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
- 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β aPADV2op 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 delegatablePADβ 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.
| 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.
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).
| File | Inference (median) | Spread (minβmax) | Runs | Peak memory |
|---|---|---|---|---|
places_fp16.tflite |
34.0 ms | 33.8β34.9 ms | 150 | 138 MB |
License
MIT. Upstream: CSAILVision/places365.
- Downloads last month
- 120
