This project implements a Siamese Network for face recognition using live video feed. The Siamese Network is trained to distinguish between different faces by learning to differentiate between pairs of images.
- Introduction
- Dataset Preparation
- Model Training
- Real-Time Application
- Dependencies
- Usage
- Contributing
- Contact
A Siamese Network consists of two identical neural networks with shared weights, which are used to find the similarity between two inputs. This project applies this concept to face recognition, allowing for real-time identification of individuals using a live video feed.
- Extract Faces: Use face detection techniques (YOLOV8) to extract faces from a collection of images or video frames.
- Create a New Dataset: Organize the extracted face images into a structured dataset. The directory structure should be as follows:
dataset/ ├── person1/ │ ├── image1.jpg │ ├── image2.jpg │ └── ... ├── person2/ │ ├── image1.jpg │ ├── image2.jpg │ └── ... └── ...
- Preprocess Images: Convert images to BGR, resize them to a fixed size, and normalize pixel values.
- Create Pairs: Generate positive and negative pairs of images. Positive pairs are two images of the same person, and negative pairs are two images of different people.
- Data Augmentation: Apply data augmentation techniques such as random rotations, shifts, flips, and zooms to increase the diversity of the training dataset and improve model robustness.
- Train Siamese Network: Train the Siamese Network using the generated pairs. The network learns to output a similarity score indicating whether two images belong to the same person.
- Capture Video: Use a webcam or any video capturing device to get a live feed.
- Preprocess Frame: For each frame, detect faces and preprocess the face images.
- Compare Faces: Compare the detected faces with known faces using the trained Siamese Network to determine if they match any known individual.
- Display Results: Display the video feed with recognition results overlayed on the detected faces.
- Python 3.9+
- TensorFlow
- ultralytics
- OpenCV
- NumPy
You can install the required dependencies using:
pip install -r requirements.txt
- Prepare Dataset: Ensure your dataset is organized as described in the Dataset Preparation section.
- Train Model: Run the training NoteBook to train the Siamese Network.
- Run Real-Time Recognition:Use the following command to start the real-time face recognition. Before run change the image path.
python main.py
Contributions are welcome! Please submit a pull request or open an issue to discuss any changes.
For any questions or inquiries, you can reach me on LinkedIn: Shukur Alam