Home

Awesome

YOLO Mask Detection

Fast scene mask detection for real world images based on the darknet framework and it's YOLOv3 Tiny PRN architecture.

Now also YOLOv4 and YOLOv4-tiny are supported!

Demo

Image Source: Twitter @BAG_OFSP_UFSP

Dataset

The dataset for this pre-trained network is provided by VictorLin000 and contains 678 images of people with and without masks. In total there are 3 different classes annotated:

You can download the dataset directly from google drive.

Training

The model has been trained on a 1080TI for about 2h over 6000 iteration with a batch size of 64 and 16 subdivisons (PRN & yolov4-tiny), 64 / 64 for yolov4.

Char

YOLOv3-tiny-prn / YOLOv4 / YOLOv4-tiny

To train the network yourself download the dataset, extract it into the training folder (/training/yolo/Mask_1.jpg) and download the initial weights into the training folder. To start the training run the following command:

darknet detector train obj.data yolov3-tiny-prn.cfg yolov3-tiny.conv.11

After the training, the resulting weights should be in the /training/backup/ folder. For instructions regarding YOLOv4, head over to AlexeyAB/darknet.

Inferencing

The weights have been trained on an image size 416x416 (PRN & tiny) / 608x608 (YOLOv4). It is also possible to inference it with a lower model size to increase the speed. A good performance / accuracy mix on CPUs has been discovered by using an image size of 128x128.

The model itself is fully compatible with the opencv dnn module and just ready to use.

Demo

There are either a python or a processing (java) demo you can run to test out your model directly with a webcam.

Python

To run the demo, please first install all the dependencies (requirements.txt) into a virtual environment and download the model and weights into the model folder (or run the shell script).

Then run the following command to start a webcam detector with Yolov3-Tiny-PRN:

# with python 3
python demo_webcam.py -n prn

# yolov4
python demo_webcam.py -s 608

# yolov4-tiny
python demo_webcam.-n tiny

Processing

For artists and makers there is also a basic example on how to use this network in Processing. The sketch itself is based on the following libraries:

Download

To download the models just run the download-models.sh in /models or use the following links:

If you are interested into the full size YOLOv3 pre-trained network, head over to this repository: VictorLin000/YOLOv3_mask_detect

About

Trained by cansik, the dataset fall under the terms and conditions of their owners (VictorLin000).

Demo images are from Unsplash: