The project is aimed to recognize every individual from a group photo consisting of several individuals.
This is achieved in Python (3.8.5), OpenCV (4.5.2), imutils (0.5.4)
The program is divided into 3 steps:
- Extract embeddings
- Responsible for using a deep learning feature extractor to generate a 128-D vector describing a face. All faces in our dataset will be passed through the neural network to generate embeddings.
- Train Model
- Our Linear SVM model will be trained by this script. We’ll detect faces, extract embeddings, and fit our SVM model to the embeddings data.
- Recognize
- We’ll recognize faces in images. We’ll detect faces, extract embeddings, and query our SVM model to determine who is in an image. We’ll upload this data to the DB. No need draw boxes.
File Structure:
- dataset*
- person 1
- person 2
- ...
- ...
- person n
- face_detection_model
- output
- embeddings.pickle
- le.pickle
- recognizer.pickle
- python_files
- extract_embeddings.py
- train_model.py
- recognize.py
- server.py
- images
- image.jpg (temp-ly)
All the python files are executed using run-script.sh script. Along with the script use any of the following arguments to perform corresponging function:
- extract
- train
- recognize
Ex: ./run-script.sh train
Output:
[INFO] loading face embeddings...
[INFO] encoding labels...
[INFO] training model...
(Note: Rename the subdirectories of the "dataset" as per the name of the person.)
File: extract_embeddings.py
Libraries used are:
- os
- cv2
- numpy
- pickle
- imutils
- argparse
- "paths" from imutils
CL-Arguments it takes:
- "--dataset" - path to input directory of faces + images
- "--detector" - path to output serialized db of facial embeddings
- "--embeddings" - path to OpenCV's deep learning face detector
- "--confidence" - minimum probability to filter weak detections
Models Used:
File: train_model.py
Libraries used:
- "LabelEncoder" from sklearn.preprocessing
- "SVC" from sklearn.svm
- argparse
- pickle
CL-Arguments it takes:
- "--embeddings" - path to serialized db of facial embeddings
- "--recognizer" - path to output model trained to recognize faces
- "--le" - path to output label encoder
Model used:
- SVC from sklearn.svm
File: recognize.py
Libraries used:
- os
- cv2
- pickle
- imutils
- argparse
- numpy
CL-Arguments it takes:
- "--image" - path to input image
- "--detector" - path to OpenCV's deep learning face detector
- "--recognizer" - path to model trained to recognize faces
- "--le" - path to label encoder
- "--confidence" - minimum probability to filter weak detections
Models Used:
File: server.py
We use a Flask Server to perform POST & GET Requests.
For Image recognition make a post request with form-data
as:
- key: image, value: "select-file"
- key: course, value: "course-name"