Face Mask Detector
Face mask classification model to detect a person wearing a mask or not. A mobilenet V2 model is trained with 97% Validation accuracy.
Model Description
- The input image shape is (150, 150, 3).
- Pre-trained Imagenet weights are employed.
- The first 10 layers of Mobilenet V2 are frozen and the model is trained.
- Batch size is 16 and SGD optimizer with learning rate is 0.01
- The Loss function is Binary cross entropy loss.
base_model = keras.applications.MobileNetV2(
input_shape= (150, 150, 3),
alpha=1.0,
include_top=False,
weights="imagenet",
pooling='avg')
for layer in base_model.layers[:10]:
layer.trainable = False
x = base_model.output
out_pred = Dense(1, activation= "sigmoid")(x)
model = Model(inputs = base_model.input, outputs= out_pred)
Setup
-
Script: test.py
-
Library Requirements: Keras, Opencv-python
- This script takes live video feed from openCV VideoCapture method.
- Loads the Face Detection Model
- Pre-process the face image
- Feed the image to the Mask Detection model
- The Model classifies the outcome
- Prints the label (Mask / No Mask ) on the image frame
Execution
> python test.py
Model Training
- Structure the Training Data Folder in the below format
data/
train/
mask/
mask001.jpg
mask002.jpg
...
no_mask/
no_mask001.jpg
no_mask002.jpg
...
test/
mask/
mask001.jpg
mask002.jpg
...
no_mask/
no_mask001.jpg
no_mask002.jpg
...
- Execute the train.py script
Dataset
Real-World Masked Face Dataset
https://github.com/X-zhangyang/Real-World-Masked-Face-Dataset