Skip to content

kristofleroux/Face-Mask-Detection-using-MobilenetV2

 
 

Repository files navigation

Face-Mask-Detection-using-MobilenetV2

Face mask detection using Pretrained MobilenetV2 using TensorFlow 2.3 and Keras API with help of Opencv's haarcascade to help with Facial recognition before feeding the data to the model.

Getting Started

Prerequisites

  • Python 3.6 or Higher
  • TensorFlow 2.x
  • opencv
  • numpy

Installing

This command will help to install the required independenies:

pip install -r requirements.txt

Nvidia GPU acceleration

To use your GPU in computing, You must install the required version of CUDA Toolkit suitable with the version of your installed Tensorflow for more help installing CUDA Toolkit visit Tensorflow site.

Dataset

The dataset came form Kaggle and had 12K examples splited into 2 class:

  • Wearing Mask.
  • Not Wearing Mask.

Which was split to 3 categories:

  • Training
  • Testing
  • Validation

To check the dataset from Kaggle you can visit this link .

Dataset Sample:

Model Architecture

The model consist of the pretrained network of MobileNetV2 with adding two extra layers to be trained on our data:

  • Flatten Layer
  • Dense layer with 2 neuron; one for each class with activation function of Softmax

The model Takes RGB images with shape of (1,128,128,3) and gives out A Vector of two Values. The First value indicates the confidence of the predication of wearing a mask. And the Second Value indicates the confidence of not wearing a mask.

Due to using Softmax Function the sum of the two Values equals to one.

MobileNetV2

Model Summary

Running The Model using Webcam

To run the model using Webcam and highlighting the faces in the feed images with a Bounding Box indicating the Prediction and the position of the face run this command

python "WebCam.py"

Prediction making

WebCam.py script uses opencv's HaarCascade to crop the faces from the input frames from the webcam. And feeds the cropped image to the trained MobileNetV2 to make a prediction and based on it a Bounding Box with the prediction will be drawn on the output.

To Terminate the program after running press ESC.

Flow Of The Image

The frame read from the WebCam maybe like this image.

Input Image

later the Haar Cascade crops out the faces in the image like this.

Cropped Faces

Then each face is fed to the MobileNetV2 individually to make a predication.

Output Image

A Bounding Box is drawn using the coordinates given by the Haar Cascade. The box indicates both predication and position of the face.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Jupyter Notebook 98.4%
  • Python 1.6%