How it works
The spoof detector uses MiniFASNet models from Silent-Face-Anti-Spoofing. It analyzes the face at two different scales to detect presentation attacks:- Crops the detected face at 2.7x scale → Model 1
- Crops the same face at 4.0x scale → Model 2
- Combines predictions using softmax averaging
- Returns spoof/real classification and confidence score
- Printed photos
- Digital screens (phones, tablets)
- Video replays
- 3D masks (with reduced accuracy)
Implementation
The spoof detector is implemented inFaceSpoofDetector.kt:36-89 as a singleton:
FaceSpoofDetector.kt
Using the detector
The detector processes face bounding boxes from the camera frame:FaceSpoofDetector.kt
Example usage
Preprocessing details
The detector performs specific preprocessing before model inference:1. Multi-scale cropping
FaceSpoofDetector.kt
2. RGB to BGR conversion
The models expect BGR color format:FaceSpoofDetector.kt
3. Softmax averaging
Predictions from both scales are combined:FaceSpoofDetector.kt
Performance tuning
By default, the detector uses CPU with 4 threads:Enabling GPU acceleration
Using NNAPI
Performance metrics
Typical inference times on mid-range devices:Accuracy considerations
The anti-spoofing models have limitations: Effective against:- Printed photos (90%+ accuracy)
- Digital screens (85%+ accuracy)
- Simple video replays (80%+ accuracy)
- High-quality 3D masks (50-70% accuracy)
- Advanced video replay attacks
- Adversarial attacks
Model sources
The TFLite models were converted from PyTorch weights:- Original PyTorch weights from deepface
- Converted via ONNX to TensorFlow
- Quantized to FP16 for mobile deployment