PlantNet-300K ResNet18 — LiteRT (plant species ID, GPU)
On-device fine-grained plant species identification — 1081 species — running
fully on the LiteRT CompiledModel GPU delegate (no CPU fallback). A
PlantNet-300K (NeurIPS 2021) ResNet18.
~16 ms/frame on a Pixel 8a.
Output:[1, 1081] species logits — softmax + top-k for the predicted species.
Labels: class index i maps to the i-th species when the PlantNet-300K
species-id strings are sorted (torchvision ImageFolder order); names from
plantnet300K_species_id_2_name.json.
GPU conversion
Plain torchvision ResNet18 — a pure CNN. It converts to a fully GPU-compatible graph
(37/37 nodes on the delegate, 1 partition; device corr 0.99999, top-1 match) with
one patch: the ResNet stem MaxPool2d(padding=1) lowers to a PADV2 with -inf
padding (PADV2: src has wrong size on the Mali delegate), replaced by an explicit
0-pad + unpadded maxpool — exact, since the maxpool input is post-ReLU (≥ 0).
CPU-exact vs PyTorch (corr 0.99999999999).
Minimal usage
Kotlin (Android, LiteRT CompiledModel GPU)
kotlin
1val options = CompiledModel.Options(Accelerator.GPU)2val model = CompiledModel.create(context.assets,"plantnet.tflite", options,null)3val inBufs = model.createInputBuffers()4val outBufs = model.createOutputBuffers()56inBufs[0].writeFloat(inputNCHW)// [1,3,224,224], RGB, ImageNet-norm7model.run(inBufs, outBufs)8val logits = outBufs[0].readFloat()// [1081]9val top = logits.indices.sortedByDescending{ logits[it]}.take(5)// species indices
Converted with litert-torch (build_plantnet.py): loads the Apache-2.0 ResNet18
weights, applies the ZeroPadMaxPool patch, and exports.
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
37 / 37
~16 ms
TFLite benchmark_model (TfLiteGpuDelegateV2)
GPU (OpenCL)
37 / 37
19.9 ms
TFLite benchmark_model
CPU (XNNPACK, 4 threads)
—
61.8 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)
This file runs on the Qualcomm Hexagon NPU as published — no conversion and no
pre-compiled artifact. LiteRT compiles it on the device and caches the result.
Measured on a physical Samsung Galaxy S26 (Snapdragon 8 Elite Gen 5 / SM8850,
Hexagon v81) with LiteRT CompiledModel 2.2.0 — 5 warm-up runs then 50 timed runs, one
accelerator per process, every row taken at device thermal status NONE.
Compute unit
Inference (median / min)
Load
Start headroom
NPU (Hexagon) — first launch
0.90 ms / 0.88 ms
586 ms
0.59
NPU (Hexagon) — cached
0.90 ms / 0.89 ms
110 ms
0.59
GPU (Adreno)
3.49 ms / 3.17 ms
464 ms
0.59
The NPU is 3.9x faster on inference here (0.90 ms against 3.49 ms). The first launch pays once for on-device compilation; every launch after that
loads in 110 ms against 464 ms for the GPU (4.2x), because the GPU rebuilds its
shaders each time. The file is fp16 and needs no int8 quantization to reach the NPU.
Running it on the NPU
Put these in jniLibs/arm64-v8a/. None of them are distributed from this repository —
the first two come from Google, the rest from Qualcomm's own SDK:
Qualcomm QAIRT — the same zip ships fetch_qualcomm_library.sh, which downloads the SDK and copies them for you
Pick the runtime matching the device's Hexagon version: SM8550 → v73, SM8650 → v75,
SM8750 → v79, SM8850 → v81.
kotlin
1val env = Environment.create(2 context,3mapOf(4 Environment.Option.DispatchLibraryDir to context.applicationInfo.nativeLibraryDir,5// Required for on-device compilation. Without it the model silently runs on CPU.6 Environment.Option.CompilerPluginLibraryDir to context.applicationInfo.nativeLibraryDir,7),8)9val options = CompiledModel.Options(Accelerator.NPU).apply{10 qualcommOptions = CompiledModel.QualcommOptions(11 htpPerformanceMode = CompiledModel.QualcommOptions.HtpPerformanceMode.BURST
12)13}14val model = CompiledModel.create(context.assets,"plantnet.tflite", options, env)
Build settings: useLegacyPackaging = true under packaging { jniLibs { … } }, so the
DSP can open the skel from a real path, and Kotlin 2.3+ for LiteRT 2.2.0's metadata.
Every NPU failure here is silent. There is no error when the NPU is unavailable —
you get a plausible CPU number instead. Confirm from logcat which delegate took the
graph: Replacing 1 out of 1 node(s) with delegate (DispatchDelegate) is the NPU,
while ... (TfLiteXNNPackDelegate) is the CPU. A missing library is reported only as
a W-level dlopen failed line under a generic No compiler plugin found summary.
On the conditions. Thermal headroom is reported as measured, where 1.0 is the
throttling threshold. All rows were taken at a comparable headroom and compare directly;
figures taken at a different headroom will differ. Each accelerator ran in its own
process, because LiteRT's Environment is shared within one and the first model load
fixes the options for every later one.
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).