Read this in 繁體中文.
2,422,339
and 2,422,210
parameters for the MFN and RMFD models, respectivelyThis app detects human faces and proper mask wearing in images and webcam streams.
Under the COVID-19 pandemic, wearing mask has shown to be an effective means to control the spread of virus. The demand for an effective mask detection on embedded systems of limited computing capabilities has surged, especially in highly populated areas such as public transportations, hospitals, etc. Trained on MobileNetV2, a state-of-the-art lightweight deep learning model on image classification, the app is computationally efficient to deploy to help control the spread of the disease.
While many work on face mask detection has been developed since the start of the pandemic, few distinguishes whether a mask is worn correctly or incorrectly. Given the discovery of the new coronavirus variant in UK, we aim to provide a more precise detection model to help strengthen enforcement of mask mandate around the world.
We provide two models trained on two different datasets. Our RMFD dataset is built from the Real World Masked Face Dataset and the MFN dataset is built from the MaskedFace-Net and Flickr-Faces-HQ Dataset (FFHQ).
This dataset consists of 4,408 images:
face_no_mask
: 2,204 imagesface_with_mask
: 2,204 imagesEach image is a cropped real-world face image of unfixed sizes. The face_no_mask
data is randomly sampled from the 90,568 no mask
data from the Real World Masked Face Dataset and the face_with_mask
data entirely provided by the original dataset.
This dataset consists of 200,627 images:
face_with_mask_correctly
: 67,193 imagesface_with_mask_incorrectly
: 66,899 imagesface_no_mask
: 66,535 imagesThe face_with_mask_correctly
and face_with_mask_incorrectly
classes consist of the resized 128*128 images from
the original MaskedFace-Net work without any sampling. The face_no_mask
is built from the
Flickr-Faces-HQ Dataset (FFHQ) upon which the MaskedFace-Net data was created.
All images in MaskedFace-Net are morphed mask-wearing images and face_with_mask_incorrectly
consists of 10% uncovered chin, 10% uncovered nose, and 80% uncovered nose and mouth images.
The dataset is now available here! (June 11, 2021)
Both models are trained on 80% of their respectively dataset and validated/tested on the other 20%. They both achieved 99% accuracy on their validation data.
MFN Model | RMFD Model |
---|---|
![]() |
![]() |
However, the MFN model sometimes classifies face_no_mask
as face_with_mask_incorrectly
. Though this would not affect
goal of reminding people to wear mask properly, any suggestion to improve the model is welcomed.
This project is built using Python 3.8 on MacOS Big Sur 11.1. The training of the model is performed on custom GCP
Compute Engine (8 vCPUs, 13.75 GB memory) with tensorflow==2.4.0
. All dependencies and packages are listed in
requirements.txt
.
Note: We used opencv-python-headless==4.5.1
due to an issue
with cv2.imshow
on MacOS Big Sur. However, recent release of opencv-python 4.5.1.48
seems to have fixed the problem.
Feel free to modify the requirements.txt
before you install all the listed packages.
cd
into where you'd like to clone this project, and clone the project:
$ git clone https://github.com/achen353/Face-Mask-Detector.git
requirements.txt
installed:
$ conda create --name env_name --file requirements.txt
cd
into the clone repository to run or inspect the code.cd
into /src/
and enter the following command:
$ python detect_mask_images.py -i <image-path> [-m <model>] [-c <confidence>]
cd
into /src/
and enter the following command:
$ python detect_mask_video.py [-m <model>] [-c <confidence>]
cd
into /src/
and enter the following command:
$ python train.py [-d <dataset>]
Make sure to modify the paths in train.py
to avoid overwriting existing models.
Note:
<image-path>
should be relative to the project root directory instead of /src/
<model>
should be of str
type; accepted values are MFN
and RMFD
with default value MFN
<confidence>
should be float
; accepting values between 0
and 1
with default value 0.5
<dataset>
should be of str
type; accepted values are MFN
and RMFD
with default value MFN
The demo of the app is available here; it is still under testing.
app.run_server(host='0.0.0.0', port=8080, debug=True)
to app.run_server(debug=True)
:$ python main.py
http://127.0.0.1:8050/
in your browser to open the app on the Dash app's default host and port. Feel free to modify
the host and port number if the default port is taken.