markdown
A real-time face verification system built using Siamese Neural Networks with TensorFlow and OpenCV. This system can learn to verify if two face images belong to the same person by computing similarity scores between facial embeddings.
- Real-time face verification using webcam input
- Siamese Neural Network architecture for one-shot learning
- Custom data collection interface for building personalized datasets
- Live verification system with adjustable thresholds
- GPU acceleration support with TensorFlow
pip install tensorflow>=2.8.0 pip install opencv-python pip install numpy pip install matplotlib pip install uuid
├── data/
├── positive/
├── negative/
├── application_data/
├── input_image/
└── verification_images/
├── training_checkpoints/
└── siamesemodelv2.h5
The model consists of:
-
Embedding Network: CNN that extracts 4096-dimensional feature vectors
- 4 Convolutional blocks with increasing filter sizes (64→128→128→256)
- MaxPooling layers for dimensionality reduction
- Dense layer with sigmoid activation for final embeddings
-
Distance Layer: Custom L1 distance calculation between embeddings
-
Classification Head: Binary classifier to determine if faces match
The network learns to:
- Minimize distance between anchor and positive pairs (same person)
- Maximize distance between anchor and negative pairs (different people)
- Use binary cross-entropy loss with Adam optimizer
python collect_data.py
Download the LFW dataset and place it in the project directory. The script will automatically move images to the negative folder.
EPOCHS = 20 train(train_data, EPOCHS)
python verify_face.py
- Detection Threshold (0.5): Minimum similarity score for positive detection
- Verification Threshold (0.5): Proportion of positive detections required for verification
- Input Size: 100×100×3 RGB images
- Batch Size: 16
- Learning Rate: 1e-4
- Embedding Dimension: 4096
The model uses precision and recall metrics during training:
- Precision: Accuracy of positive predictions
- Recall: Coverage of actual positive cases
def make_embedding(): # Modify layers, filters, or dimensions inp = Input(shape=(100,100,3), name='input_image') # Add/remove layers as needed return Model(inputs=[inp], outputs=[d1], name='embedding')
def verify(model, detection_threshold, verification_threshold): # Adjust thresholds based on your requirements # detection_threshold: 0.1-0.9 (lower = more lenient) # verification_threshold: 0.1-0.9 (lower = easier verification)
- Access Control Systems
- Identity Verification
- Security Applications
- Attendance Systems
- Personal Photo Organization
- Data Quality: Ensure good lighting and clear face visibility during data collection
- Dataset Balance: Collect similar numbers of anchor and positive samples
- GPU Memory: The script includes GPU memory growth configuration for optimal performance
- Model Saving: Model is saved as 'siamesemodelv2.h5' with custom objects
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request