A Simple Face-Mask Detector built with OpenCV, Keras(Tensorflow) in order to detect face masks in both images and video streams.
See also in: GitHub & Streamlit Cloud
TechStack/Framework
- OpenCV
- Keras(Tensorflow)
- MobileNetV2
- Optimizer: Adam
- Loss: Binary Crossentropy
- Metrics: Accuracy
- Caffe-based Face Detector
Dataset
The dataset was created by Prajna Bhandary.
The dataset consists of 1,376 images belongs to two classes:
- with_mask: 690 images
- without_mask: 686 images
The images used were real images of human faces, however artificial face masks were added to create an artificial (but still real-world applicable) dataset.
Prerequisites
All the dependencies and required libraries are included in the file
requirements.txt
.
Note: packages.txt is importing streamlit-needed exnternal dependencies. Ignore it if you are using Ananconda venv.
Results
The model gave 98% accuracy for Face Mask Detection after
training.
See also in the following accuracy/loss training curve
plot:
Working
- To train the Face-Mask Detector, execute the following sample command:
1 | python train_detector.py -d Dataset |
- To detect face masks in an single image, execute the following sample command:
1 | python predict_image.py -i .\Examples\Images\image-01.jpg |
- To detect face masks in video streams, execute the following sample command:
1 | python predict_video.py |
- To find a Web-App version of the Simple Face-Mask Detector, execute the following sample command:
1 | streamlit run Simple_Face-Mask_Detector_App.py |
or
1 | streamlit run https://raw.githubusercontent.com/Ch-i-Yu/Simple-Face-Mask-Detector/main/Simple_Face-Mask_Detector_App.py |
or simply visit Streamlit App Link.
Inspiration
This simplified, hello-world like project for a greenhand in Computer vision is inspired by the efforts of Adrian Rosebrock and Prajna Bhandary.
Special Thanks to...
Thanks for my awesome guys, Xiyu L. and Feng J. who helped me to test my tiny project and record the lovely gif in the front of this page.
License
MIT © Ch'i YU