D a t a S c i e n c e
F a c e M a s k
D e c t e c t o r

Approach

As the Covid-19 casses started to rise at an alarming rate across the whole nation, the government of India made it compulsory to wear face mask in public places.

Yet a huge number of people didn't follow the risking the life of many.

So the aim of this project was to check in real time, whether a person is wearing a face mask or not.

So I built a machine learning real time face mask checher using Python, Keras, OpenCV and MobileNet which can easily recognise if the person is wearimg face mask or not.

I used of front camera of my laptop to try out this project but it can be implanted in CCTV cameras for real life purpose.

Procedure

Step 1: Data processing

The dataset we are using consists of images with different colors, different sizes, and different orientations. Therefore, we need to convert all the images into grayscale because we need to be sure that color should not be a critical point for detecting mask. After that, we need to have all the images in the same size (100x100) before applying it to the neural network.

Step 2:Training the CNN

This consists of 2 convolutional layers (Two Convo2D 100@3x3). First, you have to load the dataset from data preprocessing. Then you have to configure the convolutional architecture. I’ve included a model.add(Dropout(0.5)) to get rid of overfitting. Since we have two categories(with mask and without mask) we can use binary_crossentropy. You start training for 20 epoch with a model checkpoint.

Step 3: Detecting Faces with and without Masks

First, you have to load the model that we created. Then we set the camera we want as the default.
Secondly, we need to label the two probabilities (0 for with_mask and 1 for without_mask). After that, we need to set the bounding rectangle color using RGB values. I’ve given RED and GREEN as two colors.
Inside an infinite loop, we are going to read frame by frame from the camera and convert them to grayscale and detect the faces. And it will be run through a for loop to for each face and detect the region of interest, resize and reshape it to 4D since the training network expects 4D input. For the model, we are going to use the best model available to get the result. This result consists of the probability (result=[P1, P2]) of the with a mask or without a mask. It will be labeled after that.

Codes

All the codes for this assignment has been uploaded on github.