A face mask detection app using a custom trained YOLOv4 model from Darknet converted to TensorFlow.
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:
- With mask
- Without mask
- Mask Weared Incorrect
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.
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 |
ย
# 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
#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
# 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
My project is based on these previous fantastic YOLOv4 implementations: