--- license: apache-2.0 library_name: litert pipeline_tag: image-classification tags: - litert - tflite - android - on-device - gpu - face-anti-spoofing - liveness - presentation-attack-detection - face --- # 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](https://github.com/minivision-ai/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](https://github.com/minivision-ai/Silent-Face-Anti-Spoofing) (`2.7_80x80_MiniFASNetV2`) · Apache-2.0. - **Size:** 1.85 MB. ![Silent-Face liveness](hero.png) *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) ```kotlin 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 != 1 ``` ### Python (LiteRT / ai-edge-litert) ```python 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. ## License Apache-2.0 (Silent-Face-Anti-Spoofing / minivision-ai).