litert-community/Silent-Face-Anti-Spoofing-LiteRT
Measured on device (edge-compat): Raspberry Pi 5 · LiteRT 2.2.0.dev20260804 · CPU/XNNPACK, 4 threads · 2.13 ms p50 (2026-08-31); browser · Chromium 151 on M4 Max · LiteRT.js 2.5.3 · WebGPU · 1.39 ms p50 · output matches CPU (2026-08-11). Record: https://github.com/john-rocky/edge-compat/blob/main/cards/silent-face-anti-spoofing/CARD.md
Silent-Face Anti-Spoofing (MiniFASNetV2) — Face liveness (LiteRT GPU)
On-device face liveness / anti-spoofing running fully on the LiteRT `CompiledModel` GPU delegate (no CPU fallback). Silent-Face-Anti-Spoofing detects presentation attacks — a printed photo or a replayed screen shown to the camera — so a live face passes and a fake is rejected. The anti-fraud building block for face login / e-KYC. Tiny (1.85 MB), ~5 ms/frame on a Pixel 8a.
- Architecture: MiniFASNetV2 (depthwise-separable CNN) — pure CNN.
- Weights: minivision-ai/Silent-Face-Anti-Spoofing (
2.7_80x80_MiniFASNetV2) · Apache-2.0. - Size: 1.85 MB.
A photographed face is correctly flagged as a replay/presentation attack. A live camera capture scores "live". Portrait: Unsplash (free license).
I/O
- Input:
[1, 3, 80, 80]NCHW, BGR,x/255— a face crop (~2.7× the face box, centered). - Output:
[1, 3]softmax — class 1 = live/real, classes 0 & 2 = spoof (print / replay). Live score =output[1];argmax == 1→ live.
GPU conversion
MiniFASNetV2 is a pure CNN → fully GPU-compatible (168/168 nodes on the delegate, 1 partition; device corr 1.0, ~5 ms) with zero patches (PReLU lowers to GPU-clean relu ops). CPU-exact vs PyTorch (corr 1.0).
Minimal usage
Kotlin (Android, LiteRT CompiledModel GPU)
val options = CompiledModel.Options(Accelerator.GPU)
val model = CompiledModel.create(context.assets, "silentface.tflite", options, null)
val inBufs = model.createInputBuffers()
val outBufs = model.createOutputBuffers()
inBufs[0].writeFloat(faceCropNCHW) // [1,3,80,80] BGR, x/255
model.run(inBufs, outBufs)
val p = outBufs[0].readFloat() // [3] softmax; live = p[1], spoof if argmax != 1Python (LiteRT / ai-edge-litert)
import numpy as np
from ai_edge_litert.interpreter import Interpreter
it = Interpreter(model_path="silentface.tflite"); it.allocate_tensors()
inp, out = it.get_input_details(), it.get_output_details()
it.set_tensor(inp[0]["index"], x) # [1,3,80,80] float32, BGR, x/255
it.invoke()
p = it.get_tensor(out[0]["index"])[0] # [3]; live = p[1]Note
The original repo ensembles two MiniFASNet models (crops at scale 2.7 and 4.0) with a face detector; this ships the primary MiniFASNetV2 (2.7). For best accuracy, feed a detected face crop and optionally ensemble the second model.
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.
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.
The NPU is 1.2x faster on inference here (0.64 ms against 0.74 ms). The first launch pays once for on-device compilation; every launch after that loads in 98 ms against 581 ms for the GPU (5.9x), 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:
Pick the runtime matching the device's Hexagon version: SM8550 → v73, SM8650 → v75, SM8750 → v79, SM8850 → v81.
val env = Environment.create(
context,
mapOf(
Environment.Option.DispatchLibraryDir to context.applicationInfo.nativeLibraryDir,
// Required for on-device compilation. Without it the model silently runs on CPU.
Environment.Option.CompilerPluginLibraryDir to context.applicationInfo.nativeLibraryDir,
),
)
val options = CompiledModel.Options(Accelerator.NPU).apply {
qualcommOptions = CompiledModel.QualcommOptions(
htpPerformanceMode = CompiledModel.QualcommOptions.HtpPerformanceMode.BURST
)
}
val model = CompiledModel.create(context.assets, "silentface.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 aW-leveldlopen failedline under a genericNo compiler plugin foundsummary.
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).
License
Apache-2.0 (Silent-Face-Anti-Spoofing / minivision-ai).
