Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Real-Time Facemask Detection using TensorFlow,

Keras, OpenCV and Convolutional Neural Network


Algorithm
Fahri Darmawan and Erry Saputra
1, a) 1, b)

Departement of Informatic Engineering of Pancasila University


1)

Lenteng Agung, South Jakarta


DKI Jakarta 12640,
Indonesia

a)
Corresponding author: 4518210001@univpancasila.ac.id
b)
4518210074@univpancasila.ac.id

Abstract. The COVID-19 pandemic has started to shake the world since December 2019. In Indonesia, as of July
2021, there have been more than two million confirmed cases of COVID-19, with more than 60,000 people having
died. Therefore, tightening health protocols is very necessary, starting from using masks, washing hands, to social
distancing. The World Health Organization says the most effective way to prevent COVID-19 is to wear a mask in
public and crowded places. It's very difficult to supervise the use of masks manually. In this study, an innovation is
proposed to monitor the use of masks in people. This system is in the form of detecting the use of masks in real time
using TensorFlow, Keras, OpenCV, and is trained and tested using the Convolutional Neural Network algorithm.
This system produces quite good results by getting an accuracy value of 99% in training, and 100% in testing.

INTRODUCTION

COVID-19 is an infectious disease caused by the newly discovered coronavirus [5]. Based on data from
the WHO, as of July 2021, there have been more than 171 million confirmed cases, of which 3 million people
have died, in Indonesia there have been more than 2 million confirmed cases, of which 60,000 have died [6].
This condition is very dangerous for human health worldwide. WHO provides recommendations for
preventive measures, one of which is the use of masks in public places and crowded places. According to the
relevant paper [9] the use of masks during the COVID-19 pandemic shows a very important implication
which is the efficacy of surgical masks for source control for coronavirus, influenza, and rhinovirus. However,
to control the use of masks on humans in public places and crowded places is a new challenge to keep
implementing health protocols during a pandemic. Considering the importance of using masks that can block
96% of the virus within eight inches of coughing from patients infected with COVID-19 [10].
Current technological advances make it easier to answer new challenges during a pandemic. Artificial
intelligence and deep learning can be used for the application of health protocols such as the use of masks
[3,4]. Machine Learning and deep learning techniques allow forecasting the spread of COVID-19 and can be
used as a way to prevent transmission of COVID-19.
The main objective of this research is to create a system to detect the use of masks in humans using deep
learning techniques. This system proposes the use of the TensorFlow, Keras, and OpenCV libraries as well
as the Convolutional Neural Network algorithm to detect people who are wearing masks or not with the help
of a camera in real time.

LITERATURE STUDY

These day there have been a lot of advancements in deep learning on object detection and recognition [7,8].
Most of it focus on face recognition for verifying identity. The aim of this experiment is to identify people
who are not wearing mask during this COVID-19 Pandemic. COVID-19 is an infectious disease that caused
by the new coronavirus [5]. A Convolutional Neural Network and TensorFlow was used in the research on
face recognition system by Liping Yuan et al [1]. On previous research on face mask detection by G. Jignesh
Chowdary et al. is using InceptionV3 on the experiment and received 99% accuracy on training and 100%
accuracy on testing [4]. A research by Chayda A. et al. for face mask detection was using a Convolutional
Neural Network for the experiment [3].
From the context above it is clear that a face mask recognition system is demanded during current world
situation, and there is a lot of study on it. Therefore, to contribute in further study of face mask recognition
to combat COVID-19, a model is proposed that used Convolutional Neural Network model with using a
library from TensorFlow.
METHODOLOGY

This research using a dataset from Kaggle [2] that has 1916 pictures of people wearing masks and 1930
pictures of people that were not wearing masks.

(a) (b)

FIGURE 1. (a) Image of people wearing mask; (b) image of people not wearing mask

FIGURE 2. Research Design

Based on the research design above. It starts with gathering the data training that used to train the model.
The training data was in image form. The image went through a preprocessing segment. In the preprocessing
segment the image was resized and the feature was extracted. And then it went through an augmentation
process where the image position was configured to make the image optimal for the training. After
preprocessing the data, the data began the training using Convolutional Neural Network with MobileNetV2.
FIGURE 3. Image representation of Convolutional Neural Network Algorithm

After training, the data model was created and was used as the database to determine whether or not the
detected image is classified as wearing a mask or not.

EXPERIMENT

FIGURE 4.(a) Shows the FIGURE 4.(b) Shows the FIGURE 4.(c) Shows the
interface when opening the application when the input data application when the input data
application is not wearing mask is wearing a mask

After following the research design, it comes as a highly accurate face mask detection application. The
result system shows high performance and has the capability to detect face masks in images with multiple
faces.

RESULT

The experiment of this research was conducted using python on Microsoft Visual Code Studio environment.
The performance metric that used is Accuracy as the formula follows:

FIGURE 5. Accuracy Formula

precision recall f1-score support


With Mask 0.99 0.99 0.99 383
Without Mask 0.99 0.99 0.99 384
Accuracy 0.99 767
Macro AVG 0.99 0.99 0.99 767
Weighted AVG 0.99 0.99 0.99 767
TABLE 1. The Performance of the model during training and testing was shown in the table.
CONCLUSION

The world is facing a huge health crisis because of pandemic COVID-19. The governments of various
countries around the world are struggling to control the transmission of the coronavirus. According to the
COVID-19 statistics published by many countries, it was noted that the transmission of the virus is more in
crowded areas. Many research studies have proved that wearing a mask in public places will reduce the
transmission rate of the virus. Therefore, the governments of various countries have made it mandatory to
wear masks in public places and crowded areas. It is very difficult to monitor crowds at these places. So in
this paper, the research proposes a deep learning system that detects persons who are not wearing a mask.
This proposed deep learning system is built using Convolutional Neural Network Algorithm. In this work
image augmentation techniques are used to enhance the performance of the model as they increase the
diversity of the training data. The proposed CNN system achieved accuracy 99% during training, and 100%
during testing.
The same work can further be improved by employing large volumes of data and can also be extended to
classify the type of mask, and implement a facial recognition system, deployed at various workplaces to
support person identification while wearing the mask. And also, Centroid Tracking was added to the
algorithm, which helped improve its performance on video streams. In times of the COVID-19 pandemic,
with the world looking to return to normalcy and people resuming in-person work, this system can be easily
deployed for automated monitoring of the use of face masks at workplaces, which will help make them safer.

ACKNOWLEDGMENTS

The authors thank Desti Fitriati, S.Kom., M.Kom. in Informatics Engineering for advice in writing and
experimenting of this paper.

REFERENCES

1. Yuan, L., Qu, Z., Zhao, Y., Zhang, H. and Nian, Q. March. A convolutional neural network based on
TensorFlow for face recognition. In 2017 IEEE 2nd Advanced Information Technology, Electronic and
Automation Control Conference (IAEAC) (pp. 525-529). IEEE. (2017)
2. Altaga. facemask-dataset [Internet]. Kaggle.com. Available from:
https://www.kaggle.com/altaga/facemaskdataset. (2020)
3. Chavda, A., Dsouza, J., Badgujar, S. and Damani, A. . April. Multi-stage cnn architecture for face mask
detection. In 2021 6th International Conference for Convergence in Technology (I2CT) (pp. 1-8).
IEEE. (2021)
4. Chowdary, G.J., Punn, N.S., Sonbhadra, S.K. and Agarwal, S., December. Face mask detection using
transfer learning of inceptionv3. In International Conference on Big Data Analytics (pp. 81-90).
Springer, Cham. (2020)
5. WHO Coronavirus (COVID-19) Dashboard [Internet]. Covid19.who.int. Available from:
https://covid19.who.int/. (2020)
6. COVID-19 W. Beranda Covid19.go.id [Internet]. covid19.go.id. Available from:
https://covid19.go.id/. (2020)
7. Zhao, Z.Q., Zheng, P., Xu, S.T. and Wu, X.. Object detection with deep learning: A review. IEEE
transactions on neural networks and learning systems, 30(11), pp.3212-3232. (2019)
8. Punn, N.S. and Agarwal, S.. August. Crowd analysis for congestion control early warning system on
foot over bridge. In 2019 Twelfth International Conference on Contemporary Computing (IC3) (pp. 1-
6). IEEE. (2019)
9. NH Leung, et al., Respiratory virus shedding in exhaled breath and efficacy of face masks. Nat.
Medicine, 1–5 (2020).
10. S Bae, et al., Effectiveness of Surgical and Cotton Masks in Blocking SARSCoV-2: A Controlled
Comparison in 4 Patients. Annals Intern. Medicine (2020).

You might also like