Skip to content

Face Mask Detection with ResNets trained with 3 labels: with_mask, without_mask, mask_weared_incorrect.

License

Notifications You must be signed in to change notification settings

DvdNss/FaceMaskDetection

Repository files navigation


Face Mask Detection using Retinanet

About The Project

This project aims to create a Face Mask Detection model to visually detect facemasks on images and videos. We operate with 3 labels:

  • with_mask
  • without_mask
  • mask_weared_incorrect

The dataset contains approximately 2500 hand-collected and hand-labelled images.

HuggingFace

Results:

Models mAP with_mask without_mask mask_weared_incorrect FPS (RTX 3060 Ti + CUDA)
ResNet50 68% 81% 67% 56% ~20
ResNet152 66% 81% 65% 52% ~12

How good are the models? This good:

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Contact

Getting Started

Installation

  1. Clone the repo
git clone https://github.com/DvdNss/FaceMaskDetection
  1. Install requirements
pip install -r requirements.txt
  1. Clone PyTorch-Retinanet
git clone https://github.com/yhenon/pytorch-retinanet.git

Usage

Structure

  • dataset/: contains datasets files
  • retinanet/: contains retinanet scripts
  • model/: contains models
  • resources/: contains readme and webapp images
  • annots_to_csv.py: script for datasets conversion to csv
  • file_conversion.py: script for png conversion to jpg
  • device.py: script for device detection (gpu or cpu)
  • precompute_dataset.py: script for dataset precomputing
  • app.py: streamlit webapp

Example

  1. Convert datasets to csv file using annots_to_csv.py
python annots_to_csv.py --train_dataset path_to_train_dataset --valid_dataset path_to_valid_dataset --output_path path_of_outputs
  1. Train a given model using pytorch-retinanet/train.py
cd pytorch-retinanet
python train.py --dataset csv --csv_train path_to_train_csv  --csv_classes path_to_class_csv  --csv_val path_to_valid_csv --depth depth_of_resnset --epochs number_of_epochs
  1. Evaluate a given model using pytorch-retinanet/csv_evaluation.py
cd pytorch-retinanet
python csv_validation.py --csv_annotations_path path_to_val_annots --model_path model_path --images_path path_to_val_img --class_list_path path_to_labels
  1. Visualize result using pytorch-retinanet/visualize_single_image.py
cd pytorch-retinanet
python visualize_single_image.py --image_dir image_dir_path --model_path model_path --class_list labels_path
  1. Use the interface (webcam or images)
streamlit run app.py

Contact

David NAISSE - @LinkedIn - [email protected]

About

Face Mask Detection with ResNets trained with 3 labels: with_mask, without_mask, mask_weared_incorrect.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages