This project implements an end-to-end face anti-spoofing classification system using DINOv3 ViT-Large architecture. The solution is designed to detect and classify spoofing attacks against face recognition systems, distinguishing between genuine faces and six different types of spoofing attacks.
Team: psi-1 Competition: Data Analytics Competition (DAC) Find IT! 2026 Metric: Macro F1-Score
Develop a multi-class face anti-spoofing classification model capable of accurately identifying whether a given face image is:
| Class | Description |
|---|---|
realperson |
Genuine face of a real individual without manipulation |
fake_printed |
Attack using printed photograph media (print attack) |
fake_screen |
Attack through digital display (smartphone/monitor) |
fake_mask |
Attack using 3D silicone mask |
fake_mannequin |
Attack using mannequin or replica face |
fake_unknown |
Other uncategorized spoofing attacks |
- Class Imbalance: Dataset has significant class imbalance (fake_mask: 500 samples vs. fake_printed: 231 samples)
- RGB-only Input: Model uses only RGB pixels without EXIF metadata
- Robustness: Ensure equal performance across all classes using Macro F1-Score evaluation
- Training Set: 2,138 images across 6 classes
- Test Set: 404 images
- Format: Images resized to 320×320 pixels with constant padding, saved as PNG
| Class | Count | Percentage |
|---|---|---|
| fake_mask | 500 | 23.4% |
| fake_screen | 376 | 17.6% |
| fake_mannequin | 378 | 17.7% |
| realperson | 371 | 17.3% |
| fake_unknown | 282 | 13.2% |
| fake_printed | 231 | 10.8% |
- Base Model: DINOv3 ViT-Large (Self-Supervised Pre-trained Vision Transformer)
- Input: RGB images (320×320 pixels)
- Output: 6-class probability distribution
- Training Strategy: Transfer learning with class-weighted loss function
✅ Reproducible Pipeline: Fixed random seeds for deterministic results ✅ No Data Leakage: Validation-based head and epoch selection ✅ Class Balancing: Weighted loss function to handle class imbalance ✅ Explainable Analysis: Comprehensive EDA and post-training insights ✅ End-to-End Workflow: From preprocessing to final submission
Macro F1-Score ensures equal contribution from all classes:
Where:
-
$TP_c$ = True Positives for class$c$ -
$FP_c$ = False Positives for class$c$ -
$FN_c$ = False Negatives for class$c$ -
$C$ = Number of classes (6)
Image-Spoofing-Classification/
├── README.md # This file
├── COMPLETE_Psi-1_Notebook.ipynb # Main end-to-end notebook
├── model/
│ └── msd_linear_best.pt # Trained model checkpoint
└── [Other directories]
- Introduction - Problem context and motivation
- Problem Statement & Competition Rules - Task definition and evaluation criteria
- Dataset Overview - Data composition and structure
- Initialization - Environment setup and reproducibility
- Exploratory Data Analysis (EDA) - Dataset insights and visualization
- Preprocessing - Image preparation and augmentation
- Modelling - Architecture design and training strategy
- Training & Submission - Model training and inference
- Reproducibility - Final submission pipeline
- Post-Insight Analysis - Model behavior analysis and insights
- Python 3.8+
- PyTorch 2.0+
- torchvision
- CUDA 11.8+ (for GPU acceleration)
- numpy, pandas, matplotlib, seaborn
- scikit-learn
- PIL (Pillow)
- NVIDIA GPU (recommended for training)
- Jupyter Notebook
-
Open the Notebook
jupyter notebook COMPLETE_Psi-1_Notebook.ipynb
-
Run Cells Sequentially
- Follow the notebook sections in order
- Each section is self-contained and documented
- Outputs will be displayed inline
-
Generate Submission
- Final cells will generate
submission.csvwith format:id,label test_0001,realperson test_0002,fake_printed ...
- Final cells will generate
The project includes a Next.js web application with both image upload and live webcam scanning features.
- Upload Mode: Upload an image file for detection
- Live Scan Mode: Real-time webcam feed with periodic detection
- Bounding Box Overlay: Visual detection boxes drawn directly on video/image
- Real-time Results: Classification labels, confidence scores, and probability breakdown
# Install Python dependencies (standard)
pip install torch torchvision timm opencv-python Pillow numpy
# For faster inference, also install ONNX Runtime
pip install onnxruntime
# Export model to ONNX (recommended for production)
python script/export_onnx.py --model model/ver34_clean_package_best.pt --output model/model.onnx
# Install Next.js dependencies
npm install
# Run development server
npm run devProblem: DINOv3 ViT-Large is a massive model (307M parameters) and inference on CPU takes 30-60 seconds.
Solutions (from fastest to slowest):
-
GPU (CUDA) ⭐ Fastest - 2-5 seconds
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu118
-
ONNX Runtime 🚀 Recommended - 5-10 seconds
pip install onnxruntime python script/export_onnx.py --model model/ver34_clean_package_best.pt
The API will automatically use ONNX if available.
-
PyTorch CPU 🐢 Baseline - 30-60 seconds
pip install torch torchvision timm opencv-python Pillow numpy
Tips for Live Scan:
- Use ONNX Runtime for real-time scanning (4-8 second intervals)
- Use GPU for true real-time (1-2 second intervals)
- Reduce webcam resolution for even faster processing
- POST
/api/detect - Form Data:
image(File) - Response: Detection results with bounding boxes and classifications
- SOLID Principles: Single responsibility components, interface-based services, dependency injection
- Security: Input validation, rate limiting (5 req/min), filename sanitization, security headers, timeout protection
- Design: Simplistic color scheme (blues, grays, whites), responsive layout, accessible components
If you want to retrain the model:
- Prepare your training data in the expected directory structure
- Update path configurations in the Initialization section
- Run the Training section
- Model checkpoint will be saved to
model/directory
- Self-supervised pre-training enables strong feature extraction without labels
- Vision Transformer (ViT) architecture provides better spatial reasoning than CNNs
- Transfer learning from ImageNet-scale pre-training reduces overfitting
- Proven performance on similar face/biometric tasks
- Loss Weighting: Inverse class frequency weighting for training loss
- Macro F1 Metric: Ensures balanced evaluation across all classes
- Stratified Splitting: Maintains class proportions in train/validation split
- Normalization: Standard ImageNet normalization (mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
- Augmentation: Controlled augmentation strategy applied consistently
- Resolution: 320×320 pixel standardization with zero-padding preservation
The trained model (msd_linear_best.pt) achieves strong performance on the test set with:
- Balanced accuracy across all spoofing attack types
- Robust detection of both common (print, screen) and sophisticated (mask, mannequin) attacks
- Macro F1-Score optimized for fair multi-class evaluation
👤 Ketua: Aufar Kusuma 👤 Anggota: Mochamad Fachri Alfaridzi 👤 Anggota: Kurt Mikhael Purba
- DINOv3: Caron et al., "DINOv3: A Vision Transformer Self-Supervised Learning Framework"
- Face Anti-Spoofing: Sundararaman et al., "Face Anti-Spoofing: A Survey" (2022)
- Class Imbalance: He & Garcia, "Learning from Imbalanced Data" (2009)
- Deep Learning: Goodfellow et al., "Deep Learning" (MIT Press, 2016)
This project is submitted as part of the Data Analytics Competition (DAC) Find IT! 2026. All rights reserved.
For questions or support, please refer to the detailed documentation within the Jupyter notebook.