Face Mask Detection using Computer Vision.

Nipun Agrawal
4 min readAug 8, 2021

Introduction:

In the Covid-19 situation, there is a need to wear the mask in public to avoid getting infected from it. Here we have build a Computer Vision model which can detect whether the person has wear the mask or not.
Before proceeding further, I am thankful to Rahul Arora for working with me on this.

Dataset Collection:

In this, we have build the model on our dataset in which it has 331 train images and 17 test images with labels mask,no mask

Images With and Without Mask

Data Annotation:

Annotation of images has been done using MakeSense.AI. This is an open source website which helps you to annotate the image and download it in any format based on our choice.
Here annotation has been done in 2 ways:
1. In .xml format, we have X-min,X-max,Y-min,Y-max coordinates

2. In .txt format it contains object class,object coordinates,image-width,image-height

Data Preparation and Modelling:

Since here we have used 2 different models, data preparation has been done on 2 different ways.
Here we will not be including all the libraries or python codes that are used as it would make this blog too lengthy. Reference would be provided in the reference section.

1. Tensorflow Object Detection with Pretrained SSD Resnet:

We have to create the .csv file from the xml.

After this we need to create train and test tf record separately.

We have trained our model for 10000 number of steps. For the final few number of steps here is what our loss looks like

As we can see from the above total loss is too much, so we are not expecting this model to work properly.
For the inference of the model, we have provided the gist below.

Lets check how our model performs.

From the above, we can clearly see that our model is not performing well enough. Either it needs to be trained for more number of steps or better model need to be used but for few final number of steps loss was not decreasing much it might be possible that we have reached the saturation point. We need to use better model.

2. YoloV5s:

Here we will be using .txt file annotation for training the model. There are different versions of yolo v5. We have initially used Yolo v5s version to check how the model performs.
We will only be posting the snippets where the changes have to be made.

Before training the model make sure your file structure looks like this:

Make sure that case of images, labels file name should be exactly else it would throw an error.
Now we would be training our model for 200 epochs with batch size of 80.
For final few epochs this is how our loss looks like.

Lets check how our model performs:

We can see that our model performs well.
Lets see how the plot looks like:

From above we can observe that our model is not overfitting at all.

Reference Links:

  1. Tensorflow Object Detetction:
    https://www.youtube.com/watch?v=XoMiveY_1Z4
  2. Yolo: https://colab.research.google.com/drive/16QCaYzTuHCOF9CQLQYmGNxmtY1xKAIdn?usp=sharing#scrollTo=dOrWg4mthaji

Github Repository:

For any contact here are our linkedin profile:
1. Nipun Agrawal https://www.linkedin.com/in/nipun-agrawal-200597110/
2. Rahul Arora https://www.linkedin.com/in/rahul-arora-461a19125/

--

--