Face Mask Detection

Intro
This code is inspired by my friend at Bangkit Academy LED by Google that want to help government to separate people who wear a mask or not.
Consider that I train this model by using pre-trained model MobileNetV2 which you can read more here about MobileNetV2: Documentation, Architecture, Dataset.
You can found other demo’s videos by following this directory ./DEMO or you can click here Demo Result or you can click this image bellow:
Dependencies
- Python 3
- tensorflow 2.1
- openCV
- matplotlib
Dataset
I load the data using Kaggle API which you can found here Face Mask ~12K Images Dataset. The size for all data is 329MB, with 10.000 images for training, 800 images for validation, and 992 images for testing.
How To Run
Step to run this file is depend on what you’re needed.
- You can clone this repository using this command
https://github.com/Cindyalifia/face-mask-detection.git
- If you just want to use face mask classification, you can download this python file
Predicting_Face_Mask.py or by following this directory to read the notebook file to make you eazier to understand line by line of code ./IPYNB_FILE/Predicting_Face_Mask.ipynb. After download it, you have to do this following steps:
- If you want to build face mask detector based on image, you need to download this python file
DETECT_FACE_MASK.py or you can follow this directory to read the notebook file IPYNB_FILE\DETECT_FACE_MASK.ipynb. These are steps that you must be followed.
- Last but not least, if you want to detect whether people wearing mask or not with video based, you can download this python file
video_face_mask_detection.py I’m not creating a notebook file, because the latency when I load the videos on the colab is very high. These are steps that you must be followed.
Design the net
Skip this if you are working with one of the original configurations since they are already there. Otherwise, see the following example:
...
[Untrainable MobileNetV2 Layer]
[AveragePooling2D]
-> pool_size=(7, 7)
[Flatten]
[Dense]
-> 512 neuron
-> activation="relu"
[Dropout]
-> 0.5
[Dense]
-> 128 neuron
-> activation="relu"
[Dropout]
-> 0.5
[Dense]
-> 2 neuron
-> activation="softmax"
...
Training the model
In the training model, these are what I got :
- Total params: 2,979,778
- Trainable params: 721,794
- Non-trainable params: 2,257,984
Since we’re not trying to retrain mobileNetV2 layer it’s affected to the total of Non-trainable params. And the rest params is from my layer that I training.
Accuracy of my model
I got this accuracy when I train my model :

I’ve got 99,75% accuracy for data validation, it’s pretty good since the model can predict a new data almost all of them.
Android deployment
Hai, for the android deployment, I already build an apps that you can run or just download it and use it on yout device. You can found it here https://github.com/Cindyalifia/tflite-face-mask-detection-android.
I build two apps, one of them is to detect face mask detection by uploading a photos through your file which you can find here FACE_MASK_DETECTION.
Another one is to build face mask detection in live stream which you can find here FACE_MASK_DETECTION LIVE_STREAMING.
评论