irsyadakbar01/revastco-facerecognizer
π― FaceMatch AI - Advanced Face Recognition System
    
An advanced facial recognition system powered by deep learning neural networks, designed for high-accuracy face matching in group photos and challenging conditions. Optimized for Hugging Face Spaces deployment.
π Ready to Deploy? This app is ready for Hugging Face Spaces! Jump to Deployment Section for step-by-step guide.
β¨ Features
π 5 Performance Tiers
- β‘ Ultra Fast Mode (~0.5-1s) - Single model, quick results
- β‘ Fast Mode (~1-2s) - Balanced speed and accuracy [RECOMMENDED]
- π― Accurate Mode (~3-5s) - 3-model ensemble for high accuracy
- π₯ HardMode (~10-20s) - 4-5 model ensemble for maximum accuracy
- β‘π₯ Extreme Mode (~5-15s) - SUPERIOR: Multi-detector + 5+ models + FAISS [BEST]
π¨ Advanced Capabilities
- β Multi-face detection - Detect and recognize multiple faces in a single photo
- β Group photo support - Optimized for 21+ people in challenging conditions
- β Multi-detector approach - RetinaFace, MTCNN, OpenCV for best detection
- β Adaptive thresholding - Quality-based threshold adjustment per face
- β Face enhancement - CLAHE, bilateral filtering, sharpening
- β Second-pass matching - Automatic retry with enhancement for unmatched faces
- β Cross-model verification - Reduces false positives significantly
- β Persistent caching - Instant load times after initial setup
- β Multi-user support - Concurrent access with session isolation
- β Admin panel - Cache management and pre-warming tools
π§ AI Models Used
- Facenet512 - High-accuracy face embeddings (weighted 1.5x)
- ArcFace - State-of-the-art face recognition (weighted 1.5x)
- VGG-Face - Robust face representation
- OpenFace - Lightweight and efficient
- SFace - Additional verification layer
- FAISS - Fast similarity search for large datasets
π¬ Quick Deployment Overview
For Hugging Face Spaces Users:
- Create Space β Choose Streamlit SDK
- Upload Files β All project files including
persistent_cache/(pre-warmed) - Set Secrets β Admin credentials in Space settings
- Launch β Instant startup with pre-warmed cache!
Time to deploy: 5-10 minutes (with pre-warmed cache) | First load: < 10 seconds β‘
π Full deployment guide below β Jump to Deployment
π Table of Contents
- Installation
- Quick Start
- Usage
- Admin Panel
- Data Preparation
- Configuration
- π Deployment to Hugging Face Spaces β
- Troubleshooting
- Performance
- Architecture
- Contributing
- Security
- License
π οΈ Installation
Prerequisites
- Python 3.8 or higher
- 4GB+ RAM (8GB recommended for Extreme Mode)
- Windows, macOS, or Linux
Step 1: Clone the Repository
git clone <your-repo-url>
cd "FaceMatch Detector"Step 2: Install Dependencies
pip install -r requirements.txtDependencies include:
- Streamlit 1.32.2 - Web interface
- DeepFace 0.0.91 - Face recognition library
- TensorFlow 2.13.0 - Deep learning framework
- OpenCV - Computer vision tools
- FAISS - Fast similarity search
- InsightFace - Additional face recognition models
- And more... (see
requirements.txt)
π Quick Start
1οΈβ£ Prepare Your Dataset
Create a students_data.json file with your face database:
{
"students": [
{
"nama": "John Doe",
"nim": "123456",
"foto": "foto rev/john.jpg",
"kelas": "A"
}
]
}Place reference photos in the foto rev/ directory.
2οΈβ£ Run the Application
streamlit run app.pyThe application will be available at: http://localhost:8501
3οΈβ£ Pre-warm Cache (Recommended)
For instant performance on subsequent runs:
Option A: Via Script (Fastest)
python prewarm_cache.pyOption B: Via Admin Panel
- Run admin panel:
run_admin.bat(Windows) or./run_admin.sh(Linux/Mac) - Access at: http://localhost:7861
- Login with default credentials (username:
admin, password:admin) - Go to "π Pre-warming" tab and click pre-warm for each mode
β±οΈ First-time setup: 60-90 minutes β‘ After pre-warming: Instant (< 1 second load time)
π Usage
Basic Recognition Flow
- Select Recognition Mode - Choose from 5 performance tiers based on your needs
- Upload Photo - Support for JPG, PNG, JPEG formats
- Adjust Threshold (Optional) - Fine-tune matching sensitivity (0.3-0.6)
- Detect Faces - AI processes the image and finds all faces
- View Results - See matched students with confidence scores and details
Recognition Modes Explained
Threshold Guidelines
- 0.30-0.35 - Very permissive (more matches, some false positives)
- 0.35-0.40 - Balanced (recommended)
- 0.40-0.50 - Strict (fewer matches, high confidence)
- 0.50-0.60 - Very strict (only very clear matches)
π§ Admin Panel
Access the admin panel to manage cache and optimize performance.
Starting Admin Panel
Windows:
run_admin.batLinux/Mac:
chmod +x run_admin.sh
./run_admin.shManual:
streamlit run admin_cache.py --server.port 7861Access at: http://localhost:7861
Admin Features
π Cache Status Tab
- View all cached modes
- Monitor storage usage
- Check cache validity
- See creation timestamps
π Pre-warming Tab
- Pre-warm each mode individually
- View progress in real-time
- Verify successful caching
π Security Settings
- Change admin credentials
- Secure your admin panel
β οΈ IMPORTANT: Change default credentials immediately!
python update_admin_password.pyπ¦ Data Preparation
Student Database Format
Create students_data.json:
{
"students": [
{
"nama": "Student Name",
"nim": "Student ID",
"foto": "foto rev/student.jpg",
"kelas": "Class Name",
"jurusan": "Major (optional)",
"angkatan": "Year (optional)"
}
]
}Photo Requirements
- Format: JPG, PNG, JPEG
- Quality: High resolution preferred (minimum 640x480)
- Face visibility: Clear, front-facing photos work best
- Lighting: Good lighting conditions
- Location: Place in
foto rev/directory - Naming: Match the filename in
students_data.json
Prepare Data Script
Use the included script to organize your data:
python prepare_data.pyβοΈ Configuration
Application Settings
Edit app.py to customize:
# Page configuration
st.set_page_config(
page_title="FaceMatch AI - Recognition System",
page_icon="π―",
layout="wide"
)Cache Configuration
Cache is automatically managed by cache_manager.py:
- Location:
persistent_cache/directory - Format: Pickle files with embeddings and metadata
- Validation: Hash-based integrity checking
- Modes: Separate cache for each recognition mode
Environment Variables
For deployment (e.g., Hugging Face Spaces):
ADMIN_USERNAME=your_username
ADMIN_PASSWORD=your_secure_passwordπ Deployment to Hugging Face Spaces
π Quick Deployment Guide
Step 1: Create Hugging Face Space
- Login to Hugging Face
- Click "New Space"
- Choose:
- SDK: Streamlit
- Space name:
facematch-ai(or your preferred name) - Visibility: Private (recommended) or Public
- Hardware: CPU Basic (Free) or upgrade for better performance
Step 2: Prepare Your Repository
Required files structure:
FaceMatch Detector/
βββ app.py # Main application β
βββ admin_cache.py # Admin panel β
βββ cache_manager.py # Cache management β
βββ requirements.txt # Dependencies β
βββ packages.txt # System packages (empty is OK) β
βββ students_data.json # Your student database β
βββ admin_config.json # Admin credentials β
βββ foto rev/ # Reference photos β
βββ persistent_cache/ # Pre-warmed cache (recommended) β
βββ README.md # This file (with HF metadata) β
Step 3: Pre-warm Cache (HIGHLY RECOMMENDED)
β οΈ IMPORTANT: Pre-warming saves 25-35 minutes of wait time for first user!
Option A: Local Pre-warming (Recommended)
# Install dependencies locally
pip install -r requirements.txt
# Run pre-warming script
python prewarm_cache.py
# This creates persistent_cache/ folder with all embeddings
# Takes 60-90 minutes but only needs to be done ONCEOption B: Use Admin Panel
# Run admin panel
run_admin.bat # Windows
./run_admin.sh # Linux/Mac
# Access at http://localhost:7861
# Login and pre-warm each modeStep 4: Upload to Hugging Face
Via Git (Recommended):
# Clone your space
git clone https://huggingface.co/spaces/YOUR_USERNAME/facematch-ai
cd facematch-ai
# Copy all files from your project
cp -r "path/to/FaceMatch Detector/"* .
# IMPORTANT: Ensure .gitignore allows persistent_cache/
# Check .gitignore doesn't have: persistent_cache/
# Add files
git add .
# Commit (may take time if including cache - ~1.2GB)
git commit -m "Initial deployment with pre-warmed cache"
# Push to Hugging Face
git pushVia Web UI:
- Go to your Space β Files
- Click "Add file" β "Upload files"
- Upload all files including
persistent_cache/folder - Commit changes
Step 5: Configure Secrets (Security)
In your Space settings β Repository secrets, add:
ADMIN_USERNAME=your_secure_username
ADMIN_PASSWORD=your_secure_passwordβ οΈ Change default credentials immediately! Default is admin/admin
# Generate new password hash locally
python update_admin_password.pyStep 6: Verify Deployment
- Wait for build - Check "Building" status in Space
- Access app - Click "Open Space" when ready
- Test recognition - Upload a test photo
- Check cache - Should load instantly if pre-warmed
- Access admin - Run admin panel separately if needed
Your Space URL: https://huggingface.co/spaces/YOUR_USERNAME/facematch-ai
π Deployment Performance
Recommendation: Always pre-warm and commit cache!
π Security Best Practices
- Change default credentials:
python update_admin_password.py- Use environment variables for sensitive data:
- Set in Space Settings β Repository secrets
- Don't commit credentials to Git
- Set visibility:
- Private: Only you can access
- Public: Anyone can use (be careful with personal data!)
- Monitor access:
- Check Space logs regularly
- Review admin panel access logs
βοΈ Advanced Configuration
Hardware Upgrades (Optional)
For better performance, upgrade Space hardware:
- CPU Basic (Free) - Suitable for small datasets (<100 students)
- CPU Upgrade ($9/month) - Better for medium datasets (100-500 students)
- GPU ($60+/month) - Fastest for large datasets (500+ students)
Multi-Page App Setup
Access admin panel as a separate page:
# Create pages directory
mkdir pages
# Move admin to pages
mv admin_cache.py pages/1_π§_Admin_Panel.pyStreamlit will auto-detect and show in sidebar!
Custom Domain (Optional)
- Upgrade to Hugging Face Pro
- Settings β Custom domain
- Follow DNS configuration steps
π Troubleshooting Deployment
β Space stuck on "Building"
Solution: Check build logs for errors. Common issues:
- Missing dependencies in
requirements.txt - Python version mismatch
- Large files timing out
β "Out of memory" error
Solution:
- Use only Fast/Accurate modes (disable HardMode/Extreme)
- Reduce cache size
- Upgrade to better hardware
β Cache not loading
Solution:
- Verify
persistent_cache/folder uploaded correctly - Check if files are Git LFS tracked (for large files)
- Re-run pre-warming
β Slow performance
Solution:
- Ensure cache is pre-warmed and committed
- Upgrade hardware
- Check Space isn't sleeping (Free tier sleeps after inactivity)
β Admin panel not accessible
Solution:
- Set up as multi-page app (see Advanced Configuration)
- Or run separately:
streamlit run admin_cache.py --server.port 7861
π Additional Resources
- π Detailed guide: See
HUGGINGFACE_DEPLOYMENT.md - π Quick start: See
QUICKSTART.md - π§ Admin guide: See
ADMIN_ACCESS_GUIDE.md - ποΈ Cache system: See
CACHE_SYSTEM_README.md
π― Deployment Checklist
Before going live, ensure:
- β All files uploaded correctly
- β Cache pre-warmed and committed
- β Admin credentials changed
- β Environment variables set
- β Student data populated
- β Reference photos uploaded
- β App tested and working
- β Admin panel accessible
- β Performance acceptable
- β Security configured
Ready to deploy? Follow the steps above! π
π Troubleshooting
Common Issues
β "Cache manager not available"
Solution: Ensure cache_manager.py exists in the project directory
β "Failed to load embeddings"
Solution: Run pre-warming script:
python prewarm_cache.pyβ Slow first run
Expected: First run takes 5-20 minutes to compute embeddings. Use pre-warming to speed up!
β Low detection rate
Solution:
- Try Extreme Mode for challenging photos
- Adjust threshold (lower = more permissive)
- Ensure reference photos are high quality
- Check lighting and face visibility
β Memory errors
Solution:
- Use lower modes (Ultra Fast or Fast)
- Reduce image resolution
- Add more RAM or use cloud deployment
β Admin panel won't start
Solution:
# Check if port is available
netstat -ano | findstr :7861
# Kill process if needed (Windows)
taskkill /PID <process_id> /F
# Restart admin panel
run_admin.batπ Performance
Speed Benchmarks
Accuracy Comparison
Based on testing with 21-person group photo:
Storage Requirements
- Application: ~50 MB
- Dependencies: ~2 GB
- Cache (all modes): ~1.2-1.5 GB
- Total: ~3.5-4 GB
ποΈ Architecture
System Components
βββββββββββββββββββββββββββββββββββββββββββββββββββ
β Web Interface (Streamlit) β
βββββββββββββββββ¬ββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββΌββββββββββββββββββββββββββββββββββ
β Face Detection & Recognition β
β βββββββββββ¬βββββββββββ¬βββββββββββ¬βββββββββββ β
β βRetinaFaceβ MTCNN β OpenCV β SSD β β
β βββββββββββ΄βββββββββββ΄βββββββββββ΄βββββββββββ β
βββββββββββββββββ¬ββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββΌββββββββββββββββββββββββββββββββββ
β Model Ensemble (DeepFace) β
β βββββββββββ¬βββββββββββ¬βββββββββββ¬βββββββββββ β
β βFacenet512β ArcFace β VGG-Face β OpenFace β β
β βββββββββββ΄βββββββββββ΄βββββββββββ΄βββββββββββ β
βββββββββββββββββ¬ββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββΌββββββββββββββββββββββββββββββββββ
β Cache Management System β
β (Persistent Embeddings Storage) β
βββββββββββββββββ¬ββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββΌββββββββββββββββββββββββββββββββββ
β Student Database (JSON + Photos) β
βββββββββββββββββββββββββββββββββββββββββββββββββββKey Technologies
- Frontend: Streamlit (Python web framework)
- Backend: Python 3.8+
- Face Detection: RetinaFace, MTCNN, OpenCV, SSD
- Face Recognition: DeepFace (Facenet512, ArcFace, VGG-Face, OpenFace)
- Deep Learning: TensorFlow, Keras
- Similarity Search: FAISS (Facebook AI Similarity Search)
- Image Processing: OpenCV, PIL, Albumentations
- Caching: Pickle-based persistent storage
π Project Structure
FaceMatch Detector/
βββ app.py # Main application
βββ admin_cache.py # Admin panel
βββ cache_manager.py # Cache management system
βββ prewarm_cache.py # Cache pre-warming script
βββ prepare_data.py # Data preparation utility
βββ update_admin_password.py # Security utility
βββ requirements.txt # Python dependencies
βββ packages.txt # System packages
βββ students_data.json # Student database
βββ admin_config.json # Admin credentials
βββ foto rev/ # Reference photos directory
βββ persistent_cache/ # Cached embeddings
βββ run_admin.bat # Windows admin launcher
βββ run_admin.sh # Linux/Mac admin launcher
βββ docs/ # Documentation
βββ QUICKSTART.md
βββ ADMIN_ACCESS_GUIDE.md
βββ CACHE_SYSTEM_README.md
βββ DEPLOYMENT_SUMMARY.md
βββ HUGGINGFACE_DEPLOYMENT.md
βββ ...π€ Contributing
Contributions are welcome! Here's how you can help:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Development Setup
# Clone repository
git clone <your-repo-url>
cd "FaceMatch Detector"
# Install dependencies
pip install -r requirements.txt
# Run in development mode
streamlit run app.py --server.runOnSave trueπ Security
Best Practices
- Change default admin credentials immediately:
python update_admin_password.py- Use environment variables for sensitive data:
export ADMIN_USERNAME=your_username
export ADMIN_PASSWORD=your_secure_password- Secure admin panel access:
- Use strong passwords
- Limit network access
- Monitor access logs
- Protect student data:
- Don't commit
students_data.jsonto public repos - Use
.gitignorefor sensitive files - Encrypt data at rest if needed
π License
This project is licensed under the MIT License - see the LICENSE file for details.
π Acknowledgments
- DeepFace - Serengil et al. for the amazing face recognition library
- Streamlit - For the intuitive web framework
- TensorFlow - Google Brain team for the deep learning framework
- FAISS - Facebook AI Research for fast similarity search
- InsightFace - For state-of-the-art face recognition models
- RetinaFace - For robust face detection
π Support
Need help? Here are your options:
- Documentation: Check the
docs/folder for detailed guides - Issues: Open an issue on GitHub
- Discussions: Start a discussion for questions and ideas
- Email: Contact the maintainer
πΊοΈ Roadmap
Planned Features
- [ ] Real-time video recognition
- [ ] Mobile app support
- [ ] REST API for integration
- [ ] Batch processing for multiple images
- [ ] Advanced analytics dashboard
- [ ] Export to Excel/PDF reports
- [ ] Multi-language support
- [ ] Cloud storage integration (S3, Google Cloud Storage)
- [ ] GPU acceleration for faster processing
- [ ] Automated attendance system
π Changelog
Version 2.1 (Current)
- β Added Extreme Mode with 90-95% accuracy
- β Multi-detector support (RetinaFace, MTCNN, OpenCV)
- β Multi-user concurrent access
- β Persistent cache system
- β Admin panel with cache management
- β Second-pass matching with face enhancement
- β Cross-model verification
- β Adaptive thresholding
Version 2.0
- β HardMode with 4-5 model ensemble
- β Enhanced UI with modern design
- β Improved accuracy algorithms
- β Better error handling
Version 1.0
- β Basic face recognition
- β Multi-face detection
- β Student database integration
π‘ Tips & Best Practices
For Best Results
- Photo Quality Matters:
- Use high-resolution reference photos
- Ensure good lighting
- Front-facing photos work best
- Choose the Right Mode:
- Daily use β Fast Mode
- Important events β Accurate or HardMode
- Large groups/challenges β Extreme Mode
- Optimize Performance:
- Pre-warm cache before deployment
- Commit cache to avoid rebuild
- Use caching for faster subsequent runs
- Threshold Tuning:
- Start with default (0.35-0.40)
- Lower for more matches (risk false positives)
- Raise for stricter matching (risk false negatives)
- Database Management:
- Keep reference photos updated
- Remove duplicates
- Use consistent naming
<div align="center">
Built with β€οΈ using DeepFace, TensorFlow, and Streamlit
β Star this repository if you find it helpful!
</div>
