Real-Time Face Mask Detector Model using Keras, Tensorflow, MobileNet and OpenCV in Python.
A Real Time COVID-19 face mask detector using OpenCV, Keras/TensorFlow, MobileNet and Deep Learning.
( A Deep Learning Case Study)
1. Introduction
Face masks are crucial in minimizing the propagation of Covid-19, and are highly recommended or even obligatory in many situations. In this project, I have developed a pipeline to detect unmasked faces in images. This can, for example, be used to alert people that do not wear a mask when entering a building.
This project consists of three steps:
- Detect all human faces in an real time using web camera.
- Make a with_mask/without_mask prediction for each of them
- Return an annotated model with the predictions
2. Real Life Applications of the Model
This face mask detector can be deployed in many areas like shopping malls, airports and other heavy traffic places to monitor the public and to avoid the spread of the disease by checking who is following basic rules and who is not.
3. Phases/Steps Involved-
4. COVID-19 face mask Source Dataset Description
Downloadable Link — https://drive.google.com/drive/folders/1Dm2sV8UrMd6OKzjVkW859WznhfSXFZF8.
The dataset used in this project work has been taken from the Kaggle.com i.e. a Faces dataset(with/without mask Dataset).
The dataset consists of 3,833 images belonging to two classes:
- with_mask: 1915 images
- without_mask: 1918 images
My goal is to train a custom deep learning model to detect whether a person is or is not wearing a mask.
5. Libraries Requirements
I have used almost all of the same libraries which are used in normal ML/DL problems like pandas, numpy, matplotlib, sklearn etc. But here I want to highlight two important libraries.
- tensorflow>=1.15.2
- keras==2.3.1
- imutils==0.5.3
- numpy==1.18.2
- opencv-python==4.2.0.*
- matplotlib==3.2.1
- scipy==1.4.1
6. Final Processing of images
MobileNet is a type of convolutional neural network designed for mobile and embedded vision applications. They are based on a streamlined architecture that uses depthwise separable convolutions to build lightweight deep neural networks that can have low latency for mobile and embedded devices.
For implementing this project four basic steps are required to be performed.
i.) Preprocessing
ii.) Face registration
iii.) Facial feature extraction
iv.) Applying Face Mask Detector Model
Test Results/ Output Screenshots
I have tested the model in real time and here also the model performed good if not perfect.
Check out the video below.
7. Future Scope
More than fifty countries around the world have recently initiated wearing face masks compulsory. People have to cover their faces in public, supermarkets, public transports, offices, and stores. Retail companies often use software to count the number of people entering their stores. They may also like to measure impressions on digital displays and promotional screens. I am planning to improve Face Mask Detection tool and release it as an open-source project. This software can be equated to any existing USB, IP cameras, and CCTV cameras to detect people without a mask. This detection live video feed can be implemented in web and desktop applications so that the operator can see notice messages. Software operators can also get an image in case someone is not wearing a mask. Furthermore, an alarm system can also be implemented to sound a beep when someone without a mask enters the area. This software can also be connected to the entrance gates and only people wearing face masks can come in.
8. Conclusion
To mitigate the spread of COVID-19 pandemic, measures must be taken. I have modeled a face mask detector using learning methods in neural networks. To train, validate and test the model, I used the dataset that consisted of 1915 masked faces images and 1918 unmasked faces images. These images were taken from various resources like Kaggle and RMFD datasets. The model was inferred on images and live video streams.
To select a base model, I have evaluated the metrics like accuracy, precision and recall and selected MobileNetV2 architecture with the best performance having 100% precision and 99% recall. It is also computationally efficient using MobileNetV2 which makes it easier to install the model to embedded systems.
This face mask detector can be deployed in many areas like shopping malls, airports and other heavy traffic places to monitor the public and to avoid the spread of the disease by checking who is following basic rules and who is not.
The entire project code is available in the following Github Repository: https://github.com/MayankBimbra/Face-Mask-Recognition-Model-using-Python/.
9. References
- https://www.researchgate.net/publication/344173985_Face_Mask_Detector
- https://www.pyimagesearch.com/2020/05/04/covid-19-face-mask-detector/
10. Full Code can be found at the link below
https://github.com/MayankBimbra/Face-Mask-Recognition-Model-using-Python/
Thank you for your time.