In the present scenario due to Covid-19, there is no efficient face mask detection applications which are now in high demand for transportation means, densely populated areas, residential districts, large-scale manufacturers and other enterprises to ensure safety. Also, the absence of large datasets of βwith_maskβ images has made this task more cumbersome and challenging. The face recognizer application which can identify the face(s) of the person(s) showing on a web cam is inspired by two path breaking papers on facial recognition using deep convoluted neural network, namely FaceNet and DeepFace.I have used pre trained model Keras-OpenFace which is an open source Keras implementation of the OpenFace (Originally Torch implemented).
Face Mask Detetction on a live video ππππππ
Face Mask Detetction on an input image ππππππ
Face Mask Detetction and Recognition on a live video ππππππ
Our face mask detector didn't uses any morphed masked images dataset. The model is accurate, and since we used the MobileNetV2 architecture, itβs also computationally efficient and thus making it easier to deploy the model to embedded systems (Raspberry Pi, Google Coral, etc.).
As far as the facial recognotion part is concerned , I have used Keras-OpenFace pre-trained model for feeding the face images to generate 128 dimensions embedding vector. OpenFace, which is an open face deep learning facial recognition model. Itβs based on the paper: FaceNet: A Unified Embedding for Face Recognition and Clustering by Florian Schroff, Dmitry Kalenichenko, and James Philbin at Google. OpenFace is implemented using Python and Torch which allows the network to be executed on a CPU or with CUDA.
Open Face Architecture ππππππ
I am using this pre-trained network to compare the embedding vectors of the images stored in the file system with the embedding vector of the image captured from the webcam. This can be explained by the below diagram.
As per the above diagram, if the face captured by webcam has similar 128-bit embedding vector stored in the database then it can recognize the person. All the images stored in the file system are converted to a dictionary with names as key and embedding vectors as value.
This system can therefore be used in real-time applications which require face-mask detection for safety purposes due to the outbreak of Covid-19. This project can be integrated with embedded systems for application in airports, railway stations, offices, schools, and public places to ensure that public safety guidelines are followed.
In one shot learning, only one image per person is stored in the database which is passed through the neural network to generate an embedding vector. This embedding vector is compared with the vector generated for the person who has to be recognized. If there exist similarities between the two vectors then the system recognizes that person, else that person is not there in the database. This can be understood by below picture.
Here we are using OpenFace pre-trained model for facial recognition. Without going into much details on how this neural network identify two same faces, let's say that the model is trained on a large set of face data with a loss function which groups identical images together and separate non-identical faces away from each other. Its also known as triplet loss function.
Please download the dataset in the dataset folder and unzip inside it . To get access tot he dataset please contact me .
This dataset consists of 10563 images belonging to two classes:
- with_mask: 7130 images
- without_mask: 3433 images
The images used were real images of faces wearing masks. The images were collected from the following sources:
- Kaggle datasets
- RMFD dataset (See here)
All the dependencies and required libraries are included in the file requirements.txt
See here
- Clone the repo
$ git clone https://github.com/vedantsahai18/COVID-Face-Mask-Detection.git
- Change your directory to the cloned repo and create a Python virtual environment named 'test'
$ mkvirtualenv test
- Now, run the following command in your Terminal/Command Prompt to install the libraries required
$ pip3 install -r requirements.txt
- Open terminal. Go into the cloned project directory folder and type the following command:
$ python train_mask_detector.py --dataset dataset
- To train facial recognition
$ python train_face_recognition.py
- To train mask detection
$ python train_mask_detector.py --datatset dataset
- Now detect the face masks in images
$ python image.py (in the code write the image path)
- To capture image of yourself ( type name and press enter and then exit/next person)
$ python capture.py
- Detection & Recognition in real-time video streams
$ python webcam.py
-
Gather actual images (rather than artificially generated images) of people wearing masks.
-
Gather images of faces that may βconfuseβ our classifier into thinking the person is wearing a mask when in fact they are not.
-
Consider training a dedicated two-class object detector rather than a simple image classifier.
Made with β€οΈ by Vedant Sahai