Face anti-spoofing (presentation-attack detection), ResNet-18 on CelebA-Spoof

Binary classifier: is the face in a photo or camera frame a live person, or an attack (printed photo, screen replay, mask, paper cut-out)? Training code, evaluation and privacy notes: github.com/haroonkhan02/face-recognition-antispoofing. Browser demo: spaces/haroonx02/face-antispoofing-browser.

ImageNet ResNet-18 fine-tuned for 8 epochs on 18,064 crops from a CelebA-Spoof subset (about 5 % of the images). The crop is a square of 1.6 Γ— the face box, kept inside the photo and resized to 128 px. The decision threshold, P(spoof) β‰₯ 0.3313, is the equal-error point on the validation split.

This repo holds only the anti-spoofing model. The face recogniser used in the project (InsightFace ArcFace, buffalo_sc) is non-commercial and is not redistributed here.

Files

File What it is Size Test APCER / BPCER
spoof_resnet18_s1.6.pt PyTorch checkpoint (state_dict, config, threshold, val EER) 45 MB 26.2 % / 1.7 %
onnx/spoof_resnet18_s1.6_fp16.onnx ONNX, FP16 weights, float32 input/output 22 MB 26.2 % / 1.7 %
onnx/spoof_resnet18_s1.6_int8.onnx ONNX, static INT8 (QDQ, per-channel, 256 training crops, MinMax) 11 MB 26.6 % / 1.6 %
onnx/spoof_resnet18_s1.6.json Threshold, crop scale and input size for clients <1 KB
onnx/yunet_2023mar_dynamic.onnx YuNet face detector from OpenCV Zoo (MIT), input shape made dynamic 0.2 MB

ONNX input crop: float32 (N, 128, 128, 3), RGB values 0–255 of the square crop (NHWC). The transpose, ImageNet normalisation and softmax are inside the graph. Output probs (N, 2) = [P(live), P(spoof)]; an attack is P(spoof) β‰₯ the threshold. To reproduce the crop, detect the face (the project uses YuNet's largest face), take a square of side 1.6 Γ— max(w, h) centred on the box, shift it back inside the image if it crosses the border (no padding), and resize with bilinear filtering.

In the INT8 file the normalisation before the first convolution and the pooling, linear head and softmax after the last one stay in float. 30 of 5,466 test decisions differ from PyTorch.

Evaluation

Split Images Result
Validation 5,194 EER 1.72 %
Test, dataset face boxes 5,466 APCER 26.2 %, BPCER 1.7 %, AUC 0.935, EER 10.6 %
Test, YuNet face boxes (as the app crops) 5,444 with a face APCER 26.5 %, BPCER 2.0 %, AUC 0.932

APCER is attacks accepted as live, BPCER is live faces rejected (ISO/IEC 30107-3). The gap between validation and test is a split problem, not noise: 77 % of sampled validation faces match a training identity against 22 % of test faces, so the threshold was calibrated on people the model had already seen. About a quarter of test attacks pass. The subset has no attack-type labels, so APCER can't be broken down per attack type.

Intended use and limits

A learning project and a baseline. It is not a security control on its own: combine it with an active challenge (the project's webcam app asks for a random head turn) and test it on your own cameras and attack types first. CelebA contains mostly lighter-skinned adult public figures, and no per-group error rates were measured.

Data and licences

Trained on CelebA-Spoof (Zhang et al., ECCV 2020), which is available for non-commercial research only; the weights inherit that restriction. The CelebA images were collected from the web without their subjects' consent to biometric research. YuNet (Wu et al., 2023) is from OpenCV Zoo under the MIT licence; only its declared input shape was changed. The training and evaluation code is MIT.

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Space using haroonx02/face-antispoofing-resnet18 1