A resource-friendly face recognition attendance system for employees, with separate modules for training, augmentation and recognition.
- Support to host system on a Flask server.
- Implicit data augmentation.
- Small, yet powerful models for feature extraction and classifiers with support for tuning hyperparameters as per dataset.
- Ease of adding new employees / removing old employees and re-training classifiers.
├───backend_support
│ ├───Models
│ │ ├───Embedder
│ │ │ openface_nn4.small2.v1.t7
│ │ │
│ │ └───Face Detection
│ │ deploy.prototxt
│ │ res10_300x300_ssd_iter_140000.caffemodel
│ │
│ └───Scripts
│ │ netSystem.py
│ │ recognizer (Not Required).py
│ │ trainer.py
│
├───Datasets
│ ├───Employee_Name_or_ID_1
│ │
│ ├───Employee_Name_or_ID_2
│ │
│ └───Employee_Name_or_ID_3
│
└───server_app
│ app.py
backend_support
: Contains models for face detection and feature extraction, and scripts that utilize them for training and recognition. Also houses embeddings and labels of faces after model is trained.Datasets
: Contains images of all employees in separate folders - each folder containing images of one individual only.server_app
: Contains a Python script to run a server application using the Flask web framework.
-
All images are first routed through a series of functions to
- perform face localization from the rest of image
- use facial landmarks for face alignment on all images
- augment all faces with different filters, skews and orientations
-
The pre-processed data is passed through OpenFace's CNN - a Torch implementation which generates 128-d representations of each image.
-
These 128-d embeddings are pickled together for each person with their respective labels, and are used for training an SVM.
For best results, please try and ensure your dataset adheres to the following:
- Ensure the face occupies at least 60% of the net image area.
- To increase adaptability, ensure your dataset has images with a variety of expressions - and with a variety of add-ons (spectacles, make-up, etc.)
- Ensure that the face is not occluded, and main features like the eyes are visibly distinct and are not covered by sunglasses.
- Ensure that the images pertaining to a person contain the face of the specific person only. Multiple faces in an image can throw the model off.
- Ensure all images are stored in folders as shown in the Usage section.
-
Add photos of your employees to the
Datasets
folder, in the following manner:- JPEG, PNG and BMP are accepted formats.
- All employees need not have the same number of images. However, ensure they have unique names or unique IDs for their respective folder names.
- For best results, please see Guidelines on data collection.
Datasets ├───Employee_Name_or_ID_1 │ Employee_ID_1_Image_1.jpeg │ Employee_ID_1_Image_2.jpeg │ Employee_ID_1_Image_3.jpeg │ ├───Employee_Name_or_ID_2 │ Employee_ID_2_Image_1.jpeg │ Employee_ID_2_Image_2.jpeg │ Employee_ID_2_Image_3.jpeg │ └───Employee_Name_or_ID_3 Employee_ID_3_Image_1.jpeg Employee_ID_3_Image_2.jpeg Employee_ID_3_Image_3.jpeg
-
Run
trainer.py
to train the classifier on your set of images.- Note that your images will be deleted from the
\Datasets
folder after training, in order to save space. To disable this feature and retain your dataset, set this line intrainer.py
toFalse
:
deleteDataset = False
- Note that your images will be deleted from the
-
New employees can be appended to the model in a similar fashion.
- Works even if the older employee datasets have been deleted. However, ensure their embeddings
(/backend_support/Embeddings and labels\Individual Embeddings)
still exist.
Datasets ├───Old_Employee_1 │ . │ . │ ├───Old_Employee_99 │ Employee_ID_99_Image_1.jpeg │ Employee_ID_99_Image_2.jpeg │ Employee_ID_99_Image_3.jpeg │ └───New_Employee_100 Employee_ID_100_Image_1.jpeg Employee_ID_100_Image_2.jpeg Employee_ID_100_Image_3.jpeg
- Works even if the older employee datasets have been deleted. However, ensure their embeddings
Run app.py
on localhost or on any production server. Post the image of the employee to the URL, and receive response with name/ID of the identified individual.