FACE MASK DETECTION MODEL

Mansi Gautam
4 min readJul 23, 2020

A deep understanding of the current COVID-19 pandemic shows how one person’s negligence can cause widespread harm. Since the general public is getting back on the streets and employees going back to their workplaces, it is extremely important for everyone to adorn face-masks as suggested by WHO, to keep themselves and others safe.

While some are following and taking this measure, some are not still not following despite official advice from the government and public health agencies. In this project, a face mask detection model that can accurately detect whether a person is wearing a mask or not is implemented to detect face masks in static images as well as in real-time video streams.

DATASET USED :

In this model we have used 2K+ images for training the model and 500+ images for testing. Dataset used has 600+ images each of mask and no_mask.

TRAINING THE MODEL :

STEP 1 : Import various libraries such as numpy , cv2, matplotlib, keras etc. and store the dataset.

STEP 2 : Images with mask and without mask are labelled and dataset is divided into training set and testing set.

STEP 3 : Next we have initialized the parameters and also created a keras model from scratch. Model has various Convolutional layers, MaxPooling2D layer, Dense layer and Dropout layer. We have used Relu as activation function in Convolutional layer.

Then we have compiled the model using Adam optimizer and used categorical_crossentropy as loss function.

The various layers can be seen in the image below.

The final layer Softmax function gives the result of two probabilities each one represents the classification of “mask” or “not mask”.

STEP 4 : 10 epochs were done in which training was done on 2213 samples and validation on 554 samples.

At the end of 10 epochs accuracy of 96.16 % was achieved and validation accuracy of 85.74 % was achieved.

STEP 5 : After the model was trained successfully , model was saved and testing was done on static image.

STEP 6 :

After successfully training the model, we save it so that we can use it in prediction.

Here we load haarcascade face detection model to detect face.Then we use while loop to take pictures continously which ultimately is what we visualize as live streaming video. Inside the while loop we first do image processing to convert our image in the form(array size reshape)we trained our model to take input. After this we give our live images to the model which predicts whether the person is wearing mask or not. After this we use “if-else” conditional statement to display text according to prediction i.e ‘‘with mask’’ or “without mask”.

INTEGRATION WITH DEVOPS

In this model we have used small dataset . There are chances that we have huge dataset and the developer might need to make small changes in code and train the complete model again. But doing this entire process manually will become a tedious task .

In order to overcome this we can integrate it with DEVOps tools like Jenkins which will automatically do this entire process as soon as it encounters any changes in code. For this we connect it with Github through PollSCM which will check the developer’s code in Github every minute and as soon as it encounters any change it will trigger the action to download the code. Further we use job chaining to trigger the next task i.e training the model after the code is downloaded from Github and then do the required predictions. In this way the developer just have to update the code and rest is done automatically through the Jenkins in a short interval of time and the client can see the updated software.

For complete procedure on integrating DEVOps with machine learning have a look at this article.

Article link: https://www.linkedin.com/pulse/integration-machine-learning-devops-mansi-das/?trackingId=AUFNLht1t4QG%2F47YCZeOnA%3D%3D

Github link: https://github.com/ManaliA23/mask_detection.git

Project Contributors: MANSI DAS and MANALI AGRAWAL

--

--