Skip to content
This repository was archived by the owner on Jun 20, 2025. It is now read-only.

Latest commit

 

History

38 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Face Mask Detection

A Deep Learning Project Using PyTorch

⚙️ Installation

  1. Clone the repository

    $ git clone https://github.com/samuel032khoury/AITermProject.git
  2. Install dependencies

    $ pip3 install -r requirements.txt
    • All the dependencies and required libraries are included in the file ./requirements.txt. See here

🗃️ Data Collection

As this program is performing a supervised learning, it needs labeled data for training & testing. The data set directory needs to be under the root of the project, and has an inner structure of:

./
├── dataset
│   ├── train                  # training data
│       ├── [Label 1]
│       ├── [Label 2]
│       └── ...
│   └── test                   # testing data
│       ├── [Label 1]
│       ├── [Label 2]
└──     └── ...

Notice labels don't have to be binary, but they have to match across the training folder and the testing folder.

Sample Data Source

🕹️ Usage

Model Training

$ python3 trainModel.py

training demo

  • CLI inputs:
    1. Data location (default = ./data)
    2. Epochs for training (default value depends on the data size)
    3. Name for the trained model

Model Running

$ python3 runModel.py
  • CLI inputs:
    1. Name of the model to use

Model Running Demo (Use the model trained by ./data_big)

running demo

🏗️ Architecture

The project used MobileNetv2 pre-trained model for transfer learning (all parameters were freezed). The produced tensor then is taken as the input to train the (modified) classifier of the model in order to make predictions.

Architecture Overview

Architecture Overview

Classifier Structure

Classifier Structure

🔬 Results & Analysis

  • The model trained with ./data after 14 Epochs have an accuracy of 88.16% (67/76).
  • The model trained with ./data_big after 2 Epochs have an accuracy of 94.07% (1349/1434).
  • Both model work well in practice in a well-lit environment.

⚠️ Limitations

  • Performance under a low-light environment is suboptimal.
  • The model cannot really distinguish between masks (any types) and other objects that can be used to cover face (plain paper, scarf, or even hands). One possible reason is the data labeled by 'no_mask' only contains bare face and ignore samples that faces being covered by ineligible masks. However, as we don't have access to a big enough data set that contains such samples at the time, our claim can't be confirmed.

⏭️ Next Step

  • Currently the project only train and use a model learned from binarily-labeled data, we want to try if the accuracy will stay the same level if we apply the algorithm on a multi label data set.

📜 Reference

  1. Deep Learning Specialization Offered By DeepLearning.AI on Coursera: Structural knowledge for DL.
  2. Extracting faces using OpenCV Face Detection Neural Network: Inspiration for extracting faces from image
  3. Face detection with OpenCV and deep learning: Inspiration for runModel.py, mostly the OpenCV part.
  4. PyTorch Official Github Profile: Reference for PyTorch relevant issue.
  5. PyTorch Tutorials: Practical material of syntax and semantics of PyTorch; Help get familiar with functions.
  6. PyTorch Vision: Official documentation as a reference for transfer learning
    • mobilenetv2: The pre-trained model the projected used
  7. Face-Mask-Detection: A similar project as a reference, also as our data set source

About

A deep learning project using PyTorch

Topics

Resources

Stars

2 stars

Watchers

2 watching

Forks

Contributors

Languages