A simple Streamlit frontend for face mask detection in images using a pre-trained Keras CNN model + OpenCV and model interpretability.
This example has been implemented as part of my evaluation of the Streamlit framework. It uses OpenCV to detect faces in the input images and a CNN as mask/no-mask binary classifier applied to the face ROI. The Deep Learning model currently used has the architecture suggested by Adrian Rosebrock here and has been trained using this image data set. The trained model has been shared in this repo. The face detector algorithm comes from here: the Caffe model and its descriptor are into the face_detector directory.
Once an image has been uploaded, the classification happens automatically. It is then possible to apply some interpretability methods for neural network understanding. The UI presents two buttons to apply the following methods:
- Grad CAM: it visualizes how parts of the input image affect a CNN output by looking into the activation maps.
- Occlusion Sensitivity: it visualizes how parts of the input image affect a CNN confidence by iteratively occluding parts.
After cloning this repository you need to create a virtual environment and install the application dependencies
pip install -r requirements.txt
Then you can execute the application through the streamlit command
streamlit run st_face_mask_detector_expl.py
Here's a demo video: