Even as travel restrictions are gradually eased with rising vaccination rates, the use of face masks continues to be important to minimize risks of transmission.
With this in mind, data science student Crystal Huang decided to build a face mask detection system using deep learning to detect whether someone is wearing a face mask, outlined in a blog post here.
For those new to AI, the steps and code offer an insight into how the ready availability of machine learning (ML) tools and the ease of Python makes it a relatively straightforward affair to build a detection system to reliably detect the presence of masks.
A mask detection system
Huang started with a variety of datasets to train a binary convolutional neural network (CNN) model using Keras/TensorFlow.
This includes the Face Mask Detection Images dataset from Kaggle of both correctly and incorrectly worn masks, additional datasets of images of masks that are worn correctly, and the CelebFaces Attributes dataset from Kaggle to beef up the dataset to 24,000 images.
To crop real-life images down to the face area for efficient detection, Huang turned to the ML-based Haar Cascade Classifier algorithm to identify faces in an image or real-time video.
The binary CNN model was then applied to each face area for its prediction. The predictions are drawn right next to the rectangle of the face area, indicating whether each detected individual is masked, unmasked, or incorrectly masked.
For real-life work, the resulting app was then built using the Streamlit app framework to generate a web app from Python-based data scripts. This can then be deployed onto a cloud PaaS platform such as Heroku to process static images or video streamed from a web camera.
Huang also advised using Google Colaboratory ('Colab' for short) for its free access to GPUs, and to start with a smaller dataset. She wrote: “When dealing with a large dataset, it’s always good to try working out a pipeline with a small set of data first. It’ll save some time on waiting for [the] model to process.”
The deployed app from Huang can be accessed here (images only).
Image credit: iStockphoto/RyanKing999