A robust and accurate face verification system that leverages state-of-the-art deep learning models to compare and verify faces across different images. This tool uses the DeepFace library and provides multiple models, detectors, and visualization options.
-
Multiple Face Recognition Models:
- ArcFace (default) - One of the most accurate face recognition models
- VGG-Face, Facenet, OpenFace, DeepID, and more
- Ensemble option that uses multiple models and votes on the result
-
Advanced Face Detection Backends:
- RetinaFace (default) - State-of-the-art face detector
- MTCNN, SSD, MediaPipe, Dlib, and OpenCV options
- Automatic fallbacks if detection fails
-
Comprehensive Analysis:
- Similarity scores and confidence levels
- Distance metrics with proper thresholds
- Detailed results with multiple metrics
- Visual comparison with automated decision
-
Flexible Options:
- Choose distance metrics (cosine, euclidean)
- Toggle face detection enforcement
- Create visualizations of results
- Debug options for troubleshooting
- Python 3.6+
- pip package manager
# Clone this repository
git clone https://github.com/subhashdasyam/compare-faces.git
cd compare-faces
# Install dependencies
pip install -r requirements.txtThe tool will automatically attempt to install DeepFace if not found on your system.
If you prefer to install dependencies manually:
pip install deepface opencv-python matplotlib numpypython deepface_recognition.py image1.jpg image2.jpgThis will:
- Compare the faces in the two images
- Generate a JSON report with similarity scores and confidence
- Create a visualization image in the output directory
python deepface_recognition.py image1.jpg image2.jpg --model ArcFaceAvailable models: VGG-Face, Facenet, Facenet512, OpenFace, DeepFace, DeepID, ArcFace, Dlib, SFace, ensemble
python deepface_recognition.py image1.jpg image2.jpg --detector retinafaceAvailable detectors: opencv, ssd, dlib, mtcnn, retinaface, mediapipe
python deepface_recognition.py image1.jpg image2.jpg --metric cosineAvailable metrics: cosine, euclidean, euclidean_l2
python deepface_recognition.py image1.jpg image2.jpg --no-enforce-detectionpython deepface_recognition.py image1.jpg image2.jpg --model ensemblepython deepface_recognition.py image1.jpg image2.jpg --no-visualizepython deepface_recognition.py image1.jpg image2.jpg --debug| Option | Description |
|---|---|
image1 |
Path to first image (required) |
image2 |
Path to second image (required) |
--model |
Face recognition model to use (default: ArcFace) |
--detector |
Face detector backend (default: retinaface) |
--metric |
Distance metric (default: cosine) |
--no-enforce-detection |
Don't enforce face detection (helpful for challenging images) |
--no-visualize |
Don't create visualization |
--debug |
Enable debug output |
{
"match": false,
"distance": 0.5623421072959899,
"threshold": 0.40000000000000036,
"similarity": 0.4376578927040101,
"confidence": "low",
"model": "ArcFace",
"detector": "retinaface",
"distance_metric": "cosine",
"processing_time": 2.345918893814087,
"message": "Match not found with low confidence (0.4377)"
}The tool generates the following files in the output directory:
verification_result.png: Visual comparison of the two images with matching resultsoriginal_img1.jpgandoriginal_img2.jpg: Original input imagesface1.jpgandface2.jpg: Extracted face regions (if detection succeeds)
If face detection fails, try the following:
- Use
--no-enforce-detectionflag - Try a different detector with
--detector mtcnnor--detector ssd - Check if the image is too low resolution or the face is too small
If you encounter issues with automatic DeepFace installation:
- Try manual installation:
pip install deepface - Check Python version (3.6+ required)
- Ensure you have proper GPU drivers if using GPU acceleration
If you get out of memory errors:
- Try a lighter model:
--model VGG-Faceor--model OpenFace - Use a less resource-intensive detector:
--detector opencv
- Python 3.6+
- DeepFace
- OpenCV
- Matplotlib
- NumPy
This project is licensed under the MIT License - see the LICENSE file for details.
- DeepFace library by Sefik Ilkin Serengil
- Face recognition models: ArcFace, VGG-Face, FaceNet, etc.
