Read this in 繁體中文.
- Features
- About
- Frameworks and Libraries
- Datasets
- Training Results
- Requirements
- Setup
- How to Run
- Dash App Demo
- Credits
- License
- Lightweight models: only
2,422,339
and2,422,210
parameters for the MFN and RMFD models, respectively - Detection of multiple faces: able to detect multiple faces in one frame
- Support for detection in webcam stream: our app supports detection in images and video streams
- Support for detection of improper mask wearing: our MFN model is able to detect improper mask wearing including (1) uncovered chin, (2) uncovered nose, and (3) uncovered nose and mouth.
This 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.
- OpenCV: computer vision library used to process images
- OpenCV DNN Face Detector: Caffe-based Single Shot-Multibox Detector (SSD) model used to detect faces
- Tensorflow / Keras: deep learning framework used to build and train our models
- MobileNet V2: lightweight pre-trained model available in Keras Applications; used as a base model for our transfer learning
- Dash: framework built upon Plotly.js, React and Flask; used built the demo app
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 images
Each 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 images
The 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.
- Open your terminal,
cd
into where you'd like to clone this project, and clone the project:
$ git clone https://github.com/achen353/Face-Mask-Detector.git
- Download and install Miniconda here.
- Create an environment with the packages on
requirements.txt
installed:
$ conda create --name env_name --file requirements.txt
- Now you can
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 ofstr
type; accepted values areMFN
andRMFD
with default valueMFN
<confidence>
should befloat
; accepting values between0
and1
with default value0.5
<dataset>
should be ofstr
type; accepted values areMFN
andRMFD
with default valueMFN
The demo of the app is available here; it is still under testing.
- Modify
app.run_server(host='0.0.0.0', port=8080, debug=True)
toapp.run_server(debug=True)
: - Run the app:
$ python main.py
- Enter
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.
- 口罩遮挡人脸数据集(Real-World Masked Face Dataset ,RMFD)
- Adnane Cabani, Karim Hammoudi, Halim Benhabiles, and Mahmoud Melkemi, "MaskedFace-Net - A dataset of correctly/incorrectly masked face images in the context of COVID-19", Smart Health, ISSN 2352-6483, Elsevier, 2020, DOI:10.1016/j.smhl.2020.100144
- Karim Hammoudi, Adnane Cabani, Halim Benhabiles, and Mahmoud Melkemi,"Validating the correct wearing of protection mask by taking a selfie: design of a mobile application "CheckYourMask" to limit the spread of COVID-19", CMES-Computer Modeling in Engineering & Sciences, Vol.124, No.3, pp. 1049-1059, 2020, DOI:10.32604/cmes.2020.011663
- Flickr-Faces-HQ Dataset (FFHQ)
- Face Mask Detection
- Object Detection