Face Mask Detection

AI-powered web application to detect face masks in real-time

Introduction

The COVID-19 pandemic highlighted the importance of wearing face masks in public places. To automate monitoring and ensure safety, I built a Face Mask Detection System using YOLOv8 for object detection and Flask for deployment. This project detects whether a person is wearing a mask, not wearing a mask, or wearing it incorrectly.

Dataset

The dataset was sourced from a public GitHub repository and contains images categorized into:

Data was organized into train, val, and test folders in YOLO format.

Model Training

The model was trained using Ultralytics YOLOv8 with the following configuration:

Training was performed on CPU with data augmentation (rotation, flipping, scaling). Results included mAP@50 = 68.2%.

Flask Web App

A Flask web application was built for easy image upload and detection. Users can drag & drop or browse an image, and the app displays predictions with bounding boxes.

Upload UI
Result UI

How It Works

  1. User uploads an image via the web interface.
  2. The Flask server saves the image and passes it to the YOLO model.
  3. The YOLO model predicts bounding boxes and labels (mask/no_mask/mask_incorrect).
  4. The processed image with predictions is displayed back in the browser.

Project Structure

face-mask-detection-starter/
│── app/
│   │── app.py
│   │── templates/index.html
│   │── static/preds/
│   │── uploads/
│── configs/data.yaml
│── requirements.txt
│── README.md
  

Results

The system successfully detects whether people are wearing masks in uploaded images. Below is an example:

Detection Result

Future Work