Skip to content

Face mask detection app using a custom trained YOLOv4 model

Notifications You must be signed in to change notification settings

tkmanabat/face-mask-detection

Repository files navigation

face-mask-detection 😷

A face mask detection app using a custom trained YOLOv4 model from Darknet converted to TensorFlow.

Dataset Used 📁

The dataset used for training was taken from Kaggle. It consists of 853 images belonging to the 3 classes, as well as their bounding boxes in the PASCAL VOC format which was later converted to text format (.txt) to be used in the Darknet framework.

It consists of 3 classes:

  1. With mask
  2. Without mask
  3. Mask Weared Incorrect

Detection Model Used 🧙

The detection model used was YOLOv4. Yolo (You Only Look Once) is one of the fastest objection detection algorithms. It can provide object detections in real-time.

These were the config and metrics of the custom YOLOv4 model trained in Darknet.

  • Used the baseline weights used in the COCO dataset.
  • Number of Epochs: 3000
  • Learning Rate: 0.001
  • Width and Height: 416x416
  • Number of classes: 3
  • Mean Average Precision (mAP): 87.02% on the dataset.

Metrics by classes 📉

Class Average Precision (AP) True Positive (TP) False Positive (FP)
With wask 94.80 % 299 37
Without mask 84.53 % 42 9
Mask weared incorrect 81.73 % 152 0

 

Usage 🧩

Install requirements or use Conda

Conda

# Tensorflow CPU
conda env create -f conda-cpu.yml
conda activate yolov4-cpu

# Tensorflow GPU
conda env create -f conda-gpu.yml
conda activate yolov4-gpu

Pip

#If you have CUDA 10.1 Toolkit you can use the GPU requirements.txt
pip install -r requirements-gpu.txt

#For CPU only machines used this
pip install -r requirements-cpu.txt

To Run

# Run detections on a webcam
python detect_video.py --weights ./checkpoints/yolov4-416 --size 416 --model yolov4 --video 0 --output ./detections/results.avi

#Run detections on an image
#Put image on /data/images and replace kite.jpg
python detect.py --weights ./checkpoints/yolov4-416 --size 416 --model yolov4 --images ./data/images/kite.jpg

Samples 📷

References 🎖️

My project is based on these previous fantastic YOLOv4 implementations:

Releases

No releases published

Packages

No packages published