COVID-19: Face Mask Detector with OpenCV, Keras/TensorFlow, and Deep Learning


In this tutorial, we’ll discuss our two-phase COVID-19 face mask detector, detailing how our computer vision/deep learning pipeline will be implemented.
From there, we’ll review the dataset we’ll be using to train our custom face mask detector.
I’ll then show you how to implement a Python script to train a face mask detector on our dataset using Keras and TensorFlow.
We’ll use this Python script to train a face mask detector and review the results.
Given the trained COVID-19 face mask detector, we’ll proceed to implement two more additional Python scripts used to:
  1. Detect COVID-19 face masks in images
  2. Detect face masks in real-time video streams
We’ll wrap up the post by looking at the results of applying our face mask detector.
I’ll also provide some additional suggestions for further improvement.

Two-phase COVID-19 face mask detector

Phases and individual steps for building a COVID-19 face mask detector with computer vision and deep learning using Python, OpenCV, and TensorFlow/Keras.

In order to train a custom face mask detector, we need to break our project into two distinct phases, each with its own respective sub-steps (as shown by Figure 1 above):
  1. Training: Here we’ll focus on loading our face mask detection dataset from disk, training a model (using Keras/TensorFlow) on this dataset, and then serializing the face mask detector to disk
  2. Deployment: Once the face mask detector is trained, we can then move on to loading the mask detector, performing face detection, and then classifying each face as 
    with_mask
     or 
    without_mask
We’ll review each of these phases and associated subsets in detail in the remainder of this tutorial, but in the meantime, let’s take a look at the dataset we’ll be using to train our COVID-19 face mask detector.

Our COVID-19 face mask detection dataset


A face mask detection dataset consists of “with mask” and “without mask” images. We will use the dataset to build a COVID-19 face mask detector with computer vision and deep learning using Python, OpenCV, and TensorFlow/Keras.
The dataset we’ll be using here today was created by PyImageSearch reader Prajna Bhandary.
This dataset consists of 1,376 images belonging to two classes:
  • with_mask
    : 690 images
  • without_mask
    : 686 images
Our goal is to train a custom deep learning model to detect whether a person is or is not wearing a mask.
Note: For convenience, I have included the dataset created by Prajna in the “Downloads” section of this tutorial.

How was our face mask dataset created?

Prajna, like me, has been feeling down and depressed about the state of the world — thousands of people are dying each day, and for many of us, there is very little (if anything) we can do.
To help keep her spirts up, Prajna decided to distract herself by applying computer vision and deep learning to solve a real-world problem:
  • Best case scenario — she could use her project to help others
  • Worst case scenario — it gave her a much needed mental escape
Either way, it’s win-win!
As programmers, developers, and computer vision/deep learning practitioners, we can all take a page from Prajna’s book — let your skills become your distraction and your haven.
To create this dataset, Prajna had the ingenious solution of:
  1. Taking normal images of faces
  2. Then creating a custom computer vision Python script to add face masks to them, thereby creating an artificial (but still real-world applicable) dataset
This method is actually a lot easier than it sounds once you apply facial landmarks to the problem.
Facial landmarks allow us to automatically infer the location of facial structures, including:
  • Eyes
  • Eyebrows
  • Nose
  • Mouth
  • Jawline

Post a Comment

1 Comments

  1. Nice post !! i am looking for this kind of post from last many days thanks for share it with us. You can also read our blog :
    Printed cotton mask

    ReplyDelete