Instructions to use litert-community/L2CS-Gaze360-LiteRT with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- LiteRT
How to use litert-community/L2CS-Gaze360-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
L2CS-Net β LiteRT (on-device gaze estimation, fully-GPU)
L2CS-Net (Ahmednull) gaze estimation, converted to LiteRT and
running fully on the CompiledModel GPU (ML Drift) on Android. Predicts where a centered face is looking
(yaw/pitch). ResNet50 backbone trained on Gaze360.
On-device (Pixel 8a, Tensor G3 β verified)
| nodes on GPU | 139 / 139 LITERT_CL (full residency) |
| inference | ~3 ms (448Γ448) |
| size | 47.9 MB (fp16) |
| accuracy | device-vs-PyTorch corr 0.9999, gaze angle within ~0.1Β° |
face[1,3,448,448] (ImageNet-normalized) β[GPU: ResNet50]β yaw[1,90], pitch[1,90] (softmax over angle bins)
The 90 bins span [-180,180]Β° (4Β° each); gaze angle = softmax expectation Ξ£ p_iΒ·i Β· 4 β 180 (softmax baked in).
Minimal usage
Android (Kotlin, CompiledModel GPU)
val model = CompiledModel.create(context.assets, "gaze_fp16.tflite",
CompiledModel.Options(Accelerator.GPU), null)
val inputs = model.createInputBuffers()
val outputs = model.createOutputBuffers()
inputs[0].writeFloat(chw) // [1,3,448,448] ImageNet-normalized RGB, NCHW
model.run(inputs, outputs)
val yawProbs = outputs[0].readFloat() // [1,90] softmax over 4-deg bins
val pitchProbs = outputs[1].readFloat() // [1,90]; deg = sum(p_i * i) * 4 - 180
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
img = Image.open("face.jpg").convert("RGB").resize((448, 448)) # centered face crop
x = ((np.asarray(img, np.float32) / 255 - MEAN) / STD).transpose(2, 0, 1)[None]
it = Interpreter(model_path="gaze_fp16.tflite"); it.allocate_tensors()
it.set_tensor(it.get_input_details()[0]["index"], x); it.invoke()
od = it.get_output_details() # output 0 = yaw, 1 = pitch (both [1,90])
deg = lambda p: float((p * np.arange(90)).sum() * 4 - 180)
yaw, pitch = (deg(it.get_tensor(o["index"])[0]) for o in od)
print(f"yaw {yaw:+.1f} deg, pitch {pitch:+.1f} deg")
How it converts (litert-torch)
Pure CNN (ResNet50 + 2 FC heads). Two numerically-exact ResNet fixes:
- stem
MaxPool2d(3,s2,p1)β zero-pad + valid max-pool β PyTorch's max-pool pads with-infβ aPADV2the Mali delegate won't delegate (compile fail); since the pool follows a ReLU, a 0-pad is exactly equivalent βPAD, full GPU residency. - global
AdaptiveAvgPool2d(1)βmean(3).mean(2).
Result: banned ops NONE, all tensors β€4D, tflite-vs-torch corr 1.0, device-vs-torch corr 0.9999.
Preprocessing & decode
Center-crop to a (centered) face, resize 448Γ448, /255, ImageNet mean/std, NCHW. Decode: softmax expectation over the 90 bins β yaw/pitch degrees β gaze direction.
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 | 139 / 139 | ~3 ms |
TFLite benchmark_model (TfLiteGpuDelegateV2) |
GPU (OpenCL) | 139 / 139 | 45.3 ms |
TFLite benchmark_model |
CPU (XNNPACK, 4 threads) | β | 541.7 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.08x faster than the GPU (3.59 ms against 11.05 ms) and loads 9.27x faster (126 ms against 1172 ms).
| backend | compiled | inference (median / min) | load |
|---|---|---|---|
| NPU (Hexagon v81) | on-device JIT | 3.59 ms / 3.53 ms | 126 ms |
| GPU (Adreno) | β | 11.05 ms / 10.69 ms | 1172 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.77β0.77, 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 5.4 s 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.
License
MIT. Upstream: Ahmednull/L2CS-Net.
- Downloads last month
- 75
