Skip to content

mmphego/face_mask_detection_openvino

Repository files navigation

Face Mask Detection using OpenVINO

Details
Programming Language: Python 3.7
Intel OpenVINO ToolKit: OpenVINO 2020.2
Docker (Ubuntu OpenVINO pre-installed): mmphego/intel-openvino
Hardware Used: Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
Device: CPU
Blog Post blogpost
Visitors

Face Mask Detection application uses Deep Learning/Machine Learning to recognize if a user is not wearing a mask and issues an alert.

By utilizing pre-trained models and Intel OpenVINO toolkit with OpenCV. This enables us to use the async API which can improve overall frame-rate of the application, rather than wait for inference to complete, the application can continue operating on the host while accelerator is busy.

This application executes 2 parallel infer requests for the Face Mask Detection and Face Detection networks that run simultaneously.

Using a set of the following pre-trained models:

  • face-detection-adas-0001, which is a primary detection network for finding faces.
  • face-mask-detection, which is a pretrained model for detecting a mask.

This application can be improved and then integrated with CCTV or other types cameras to detect and identify people without masks in public areas such as shopping centres and etc. This the ever increasing COVID-19 cases world-wide these application could be useful in controlling the spread of the virus.

Screenshot from 2020-06-01 22-21-47

What is OpenVino?

OpenVino (OpenVisual Inferencing and Neural Network Optimization) is toolkit to develop Deep Learning Application especially for Computer Vision by Intel. OpenVino Enables deep learning inference at the edge and supports heterogeneous execution across computer vision accelerators—CPU, GPU, Intel® Movidius™ Neural Compute Stick, and FPGA—using a common API. read more

You might also be interested on reading about AI At The Edge - An Introduction To Intel OpenVINO Toolkit.

Support

If you have found this useful, please donate by clicking on the image below:

image

Tutorial

Blog Post

I have created a detailed blog post on the implementation: https://blog.mphomphego.co.za/blog/2020/06/02/Face-Mask-Detection-using-Intel-OpenVINO-and-OpenCV.html

YouTube Tutorial

The first of many...

Watch the video

Hardware Requirement

  • Minimum Intel Gen 6 processors

Installation

  • Download the docker images with a pre-installed version of OpenVINO 2020.2
docker pull mmphego/intel-openvino
  • Download the facemask detection model.
wget https://github.com/didi/maskdetection/raw/master/model/face_mask.caffemodel
wget https://raw.githubusercontent.com/didi/maskdetection/master/model/deploy.prototxt
  • Convert model to OpenVINO's Intermediate Representations (IR) using the Model Optimizer, which will produce .xml and .bin files.
docker run --rm -ti \
--volume "$PWD":/app \
--env DISPLAY=$DISPLAY \
--volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" \
mmphego/intel-openvino \
bash -c "/opt/intel/openvino/deployment_tools/model_optimizer/mo.py \
    --framework caffe \
    --input_model face_mask.caffemodel \
    --input_proto deploy.prototxt"
  • Download face detection model from the model zoo, which will produce .xml and .bin files.
docker run --rm -ti \
--volume "$PWD":/app \
--env DISPLAY=$DISPLAY \
--volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" \
mmphego/intel-openvino \
bash -c "/opt/intel/openvino/deployment_tools/open_model_zoo/tools/downloader/downloader.py \
    --name face-detection-adas-0001 \
    --precision FP16"

Usage

$ python main.py -h

usage: main.py [-h] -f FACE_MODEL -m MASK_MODEL -i INPUT [-d DEVICE]
               [--face_prob_threshold FACE_PROB_THRESHOLD]
               [--mask_prob_threshold MASK_PROB_THRESHOLD] [--enable-speech]
               [--tts TTS] [--ffmpeg] [--show-bbox] [--debug]

optional arguments:
  -h, --help            show this help message and exit
  -f FACE_MODEL, --face-model FACE_MODEL
                        Path to an xml file with a trained model.
  -m MASK_MODEL, --mask-model MASK_MODEL
                        Path to an xml file with a trained model.
  -i INPUT, --input INPUT
                        Path to image or video file or 'cam' for Webcam.
  -d DEVICE, --device DEVICE
                        Specify the target device to infer on: CPU, GPU, FPGA
                        or MYRIAD is acceptable. Sample will look for a
                        suitable plugin for device specified (CPU by default)
  --face_prob_threshold FACE_PROB_THRESHOLD
                        Probability threshold for face detections filtering
                        (Default: 0.8)
  --mask_prob_threshold MASK_PROB_THRESHOLD
                        Probability threshold for face mask detections
                        filtering(Default: 0.3)
  --enable-speech       Enable speech notification.
  --tts TTS             Text-to-Speech, used for notification.
  --ffmpeg              Flush video to FFMPEG.
  --show-bbox           Show bounding box and stats on screen [debugging].
  --debug               Show output on screen [debugging].

Example Usage

make run-bootstrap

ezgif-4-993045572ebb

Packaging the Application

We can use the Deployment Manager present in OpenVINO to create a runtime package from our application. These packages can be easily sent to other hardware devices to be deployed.

To deploy the application to various devices using the Deployment Manager run the steps below.

Note: Choose from the devices listed below.

DEVICE='cpu' # or gpu, vpu, gna, hddl
docker run --rm -ti \
--volume "$PWD":/app \
mmphego/intel-openvino bash -c "\
  python /opt/intel/openvino/deployment_tools/tools/deployment_manager/deployment_manager.py \
  --targets ${DEVICE} \
  --user_data /app \
  --output_dir . \
  --archive_name face_mask_detection_${DEVICE}"

Credit