In the recent times of the pandemic, first line protection against the contract of disease is using a face mask. When going out, it is essential to cover our face(nose and mouth) with a mask. The project developed is a Convolutional Neural Network which detects whether a person is wearing a face mask or not.
I have taken a comprehensive dataset 3 seta of images containing images of two classes Mask and No mask. I have trained the model using Keras Sequential model with Adam optimising by performing training by varying different attributes of images in about 30 Epochs.
I have saved the model as as MD5 model 'FaDetNet.h5'.
Testing is done by two ways i.e. using a video input and photo input.I have used Opencv library of python for integrating the web cam of the laptop to capture images and video which are tested with the prediction function of the trained model to get a binary output.In case of image, if more number of captured images are predicted as No Mask then output will be given as NO Mask else it will be given as Mask and in case of video, all the faces present in each frame are checked for masks using trained model and result is shown above the face and a Beep Sound is given if there is no mask.
- Python 3 Environment (Ancaonda preferred)
- Python modules required:NumPy,Pandas,Opencv2,Matplotlib, Scikit-learn, Keras
- Web Browser
OR
- Any Python3 IDE installed with above modules.
- Anaconda Jupyter Notebook
Dataset is taken from a data source from a Challenge on Kaggle. It contains 3 folders of images namesly Train,Test and Validate. Each contains pictures of 2 classes No mask and Mask.
- The training set is an essential component of the network. We use dataset from a challenge in kaggle
- Dataset contains images of two defined classes
- We train the model using Keras sequential API of Tensorflow to train the model in various aspects and different angles and ranges of picture properties. We train the model in 30 epochs for gaining good accuracy. We save the model as FaDetNet.h5 for further testing and implementing of trained model.
- We use methods in OpenCV library to capture images using the web camera of laptop and save the a set of 10 images in a rapid succession to test the model trained.
- These images are saved into a seperate folder 'input'
- The images recorded are tested using the predict method of the model trained earlier i.e., FaDetNet.h5.
- All the images are tested to get output Mask or No Mask. If the number of Mask outputs are greater than No mask outputs, the Final output is given as Mask and vice versa.
- We use methods in OpenCV library to capture a video using the web camera of laptop and save the video to test the model trained.
- These video is saved into 'input'
- The video recorded is divided into a definite number of frames and each frame is tested using the predict method of the model trained earlier i.e., FaDetNet.h5.
- Then the result is shown by highlighting faces in each frame of the video as No Mask and Mask.
- If Mask is not detected on the face, A beep sound alert is given.
- Kamal Yeshodhar Shastry Gattu
GitHub: G K Y SHASTRY
Contact me: gkyshastry0502@gmail.com , kysgattu0502@gmail.com
[1] COVID Face Mask Detection Dataset
For Trained Model Run FaDetNet.ipnyb or FaDetNet.py or just send me an email ;-)