Face Mask Detection in Images utilizing BigML API
This facemask detector application leverages a neural network to perform object detection using the BigML API to determine whether people in an image are 1) Wearing a mask, 2) Not wearing a mask, or 3) Wearing a mask incorrectly.
The data was obtained from a public face mask detection dataset on Kaggle . The data contains 853 images pre-labeled with 3 object classes: with_mask, without_mask, and mask_weared_incorrect. Each image has a corresponding XML file with bounding boxes listed in PASCAL VOC format.
Figure 1. An example image from the dataset with bounding boxes around object labels.
BigML accepts object labels in JSON format, so the bounding box labels were converted from individual XML files into a single JSON document.
The data set was divided into an 80/20 train/test split. The training images were resized to 640x640 to homogenize the data and to reduce model training time. The images were resized without maintaining aspect ratio to introduce more variation when training the model. This resized dataset was used to train the final model used in this project.
Additional models were generated using augmented data sets generated by applying different combinations of the following augmentations to the original data. However, utilizing augmented images as training data caused the model performance to be worse so they were excluded when training the final model:
Rotation: Between -10° and +10° Shear: ±5° Horizontal, ±5° Vertical Blur: Up to 2.5px
Object detector Model Training
The augmented image data and labels were uploaded to BigML as a composite source and a dataset was generated. A Deepnet (BigML’s optimized version of a deep neural network) classifier was trained on the training split using the Adam Gradient Descent Optimization Algorithm.
Figure 2. Screenshot of overall model performance.
The classifier was then evaluated using the test split. Figures 3 and 4 are screenshots showing an example ROC curve and a summary of the model evaluation using the test split data, respectively.
Figure 3. A screenshot of the ROC curve and model performance for detection of people wearing masks.
Figure 4. A summary of the models overall performance with generating predictions using the test split data.
The application was deployed on the streamlit.io cloud from this GitHub repository. This application is powered using the BigML api to generate object detection predictions. This web application allows users to upload an image and have any detections displayed. Alternatively, a user can choose to use one of many example images.
Figure 5. The Face Mask Detection web application, deployed on streamlit.io cloud.
Figure 6. A sample output of mask detections from the application.
This blog post was used as a template for streamlit.io application.