This is a face recognition project that utilizes the MTCNN (Multi-task Cascaded Convolutional Networks) algorithm for face detection and the SVM (Support Vector Machines) classifier for face recognition. It also incorporates the FaceNet model for generating face embeddings.
- Clone the repository or download the code files.
- Make sure you have the following dependencies installed:
- TensorFlow
- PIL
- numpy
- mtcnn
- keras-facenet
- scikit-learn
- OpenCV
- pickle5
- Create a folder named "SVM_MTCNN" in your local directory.
- Place the code files inside the "SVM_MTCNN" folder.
- Create a folder named "database" inside the "SVM_MTCNN" folder.
- Inside the "database" folder, create subfolders for each person and place their respective face images inside those folders. Each person's folder should contain multiple face images for training.
- Example structure:
SVM_MTCNN/ ├── database/ │ ├── person1/ │ │ ├── image1.jpg │ │ ├── image2.jpg │ │ └── ... │ ├── person2/ │ │ ├── image1.jpg │ │ ├── image2.jpg │ │ └── ... │ └── ... └── ...
- Example structure:
- Open a terminal or command prompt and navigate to the directory containing the "verify.py" file.
- Run the command
python verify.py
to train the face recognition model. - The training process will load the face images, detect faces using MTCNN, generate embeddings using FaceNet, and train an SVM classifier. The trained model will be saved in a file named "model.pkl".
- The training data and embeddings will be compressed and saved in a file named "data.npz" for future use.
- Run the command
python fclassification.py
to start the face classification script. - The script will access the webcam and start capturing frames.
- It will detect faces in the frames using MTCNN and generate embeddings using FaceNet.
- The SVM model will be loaded from the "model.pkl" file.
- The script will classify the faces based on the embeddings using the SVM model.
- If a face is recognized, the person's name and classification probability will be displayed on the frame.
- If a face is not recognized, the frame will display "face not recognized".
- Press 'q' to exit the classification.
- Run the command
python cv.py
to capture and save face images for the training dataset. - Follow the prompts to enter the name of the person for whom you want to capture images.
- The webcam will start capturing frames and saving images in the corresponding folder inside the "database" directory.
- Press 'q' to stop capturing images.
- MTCNN - Multi-task Cascaded Convolutional Networks for face detection.
- keras-facenet - Pretrained FaceNet model for face recognition.
- scikit-learn - Machine learning library for SVM classifier.
- OpenCV - Computer vision library for webcam access and image manipulation.
- pickle5 - Pickle module supporting protocol version 5 for model serialization.
- PIL - Python Imaging Library for image processing.
- numpy - Library for numerical operations and array manipulation.
This project is licensed under the MIT License.