You are on page 1of 18

C.V.

RAMAN GLOBAL UNIVERSITY,


BHUBANESWAR, ODISHA
A Case Study
On

FACE MASK DETECTION SYSTEM


USING CONVOLUTIONAL NEURAL
NETWORK

Under Supervision Of:


Mr. Manas Ranjan Mishra Sir
DEPARTMENT OF CSE

STUDENT NAME REGD.


NO.
SAI ARPAN PATRA 20010346
PRATHAM AGRAWAL 20010376
SAYED AATIF 20010373
SHABAN
GARV KHANDELWAL 20010336
ABSTRACT
In December 2019, transmission of the novel Covid (SARS‐ CoV‐ 2) that
causes Covid disease 2019 (COVID‐ 19) happened in city, China. What later
took the infection to be sent from one individual to another. Face covers are a
kind of non‐public ensuring
instrumentality want to stop the unfurl of digestion contaminations, and it ought
to be compelling at serving to stop transmission of digestion infections and
bacterium. Here, we tend to share an instance of face covers are becoming
acclimated to hinder the
transmission of COVID‐ 19 disease. Henceforth, the cover acknowledgment
keeps on being a troublesome drawback in pc vision. It depicted the inventive
goal that gives conservative veil and profound learning with convolutional
neural organizations
(CNNs) has made pleasant progress inside the arrangement of cover like human
security. a spread of neuron‐wise and layer‐wise mental picture ways were applied
utilizing a CNN, prepared with an openly offered from given picture dataset.
Thus, it's resolved that neural organizations will catch the shadings and surfaces
of sores explicit to a few veils, that looks like human dynamic.
Table of Contents

CHAPTER NO. TITLE PAGE


NO. ABSTRACT
LIST OF
TABLES LIST
OF FIGURES
LIST OF SYMBOLS, ABBREVIATIONS
1. INTRODUCTION 1
1.1 OVERVIEW 1
2. LITERATURE STUDY 2
2.1 WORKS RELATED TO FACE MASK DURING COVID-19 2
2.1.1 MULTI-POINT HEAD MAKE CLASSIFICATION ONCE
CONVEYING THE SHIELD OF FACIAL RECOGNITIONS UNDER 2
THE COVID-19 VIRUS EPIDEMIC
4. APPENDIX 3
5. RESULTS
5.1 FACE MASK DETECTION 8
6. CONCLUSION 10
6. REFERENCES 11
LIST OF TABLES

2.1 Workflow Model……………………………………..………..2


2.2 Design Architecture………………………………………….. 3
LIST OF FIGURES

1.1 Workflow Model............................................................................2


2.1 Design Architecture…....................................................................3
5.1 Output.............................................................................................10
5.1 Output.............................................................................................11
ABBREVIATIONS

AI Artificial Intelligence
ML Machine Learning
DL Deep Learning
GUI Graphical User Interface
RAM Random Access Memory
CNN Convolutional Neural Network
INTRODUCTION:
COVID-19 is a respiratory disorder that results in severe cases of pneumonia in
affected individuals [14]. The disease is acquired via direct contact with an
infected person, as well as through salivation beads, respiratory droplets, or nasal
droplets released when the infected individual coughs, sneezes, or breathes out the
virus into an airspace [16]. Globally, thousands of individuals die from the
COVID-19 virus daily.
Therefore, people should wear face masks and keep a social distance to avoid
viral spread of disease. An effective and efficient computer vision strategy
intends to develop a real-time application that monitors individuals publicly,
whether they are wearing face masks or not. The first stage to identify the
existence of a mask on the face is identifying the face. This divides the whole
procedure into two parts: face detection and mask detection on the face.
Computer vision and image processing have an extraordinary impact on the
detection of the face mask. Face detection has a range of case applications, from
face recognition to facial movements, where the latter is required to show the face
with extremely high accuracy [10]. As machine learning algorithms progress
rapidly, the threats posed by face mask detection technology still seem effectively
handled. This innovation is becoming increasingly important as it is used to
recognize faces in images and in real- time video feeds.

The major contribution of the proposed work is given below:


1. Created a facemask detector implemented in three phases to assist
in precisely detecting the presence of a mask in real-time using
images and video streams.

2. The dataset is made available on GitHub that consists of masked


and unmasked images. This data set can be used to create new face
mask detectors and use them in a variety of applications.

3. The proposed model has used some popular deep learning


methods to develop the classifier and gather photos of an
individual wearing a mask and distinguish between face masks
and non-face mask classes. This work is implemented in Python
along with Open-CV and Keras. It requires less memory and
computational time in comparison to other models discussed later
Section 5 which makes it easy to deploy for surveillance.

4. The study offers future research recommendations based on the


findings for developing reliable and effective AI models that can
recognize faces in real-life situations.
WORKS RELATED TO FACE MASK DURING COVID-19:

During the COVID-19 pandemic, face mask detection has become an


essential task for ensuring compliance with health guidelines and reducing the
spread of the virus. Here are some works related to face mask detection during
COVID-19:

"Real-time face mask detection using deep learning neural networks" by Al-
Qassas et al. (2020): This paper proposes a real-time face mask detection system
using deep learning neural networks. The system uses a pre-trained convolutional
neural network (CNN) to detect faces and then another CNN to detect whether the
person is wearing a mask or not.

"COVID-19 mask detection using deep learning and computer vision" by


Prasad et al. (2020): This paper presents a deep learning and computer vision-
based face mask detection system that uses a CNN to classify whether a person
is wearing a mask or not. The system achieved an
accuracy of 98% in detecting whether a person is wearing a mask.

"Facial mask detection using convolutional neural networks: YOLOv4 and Faster
R-CNN" by Nguyen et al. (2021): This paper compares two object detection
models, YOLOv4 and Faster R-CNN, for face mask detection. The models were
trained on a dataset of images of people wearing and not wearing masks, and the
results showed that both models achieved high
accuracy in detecting whether a person is wearing a mask.
 MULTI-POINT HEAD MAKE CLASSIFICATION ONCE
CONVEYING THE SHIELD OF FACIAL RECOGNITIONS UNDER
THE COVID-19 VIRUS EPIDEMIC:-

o Wearing masks is essential during the pandemic, but it can


create problems in expressing facial information.
o There is a need for research on awareness and expression
presentation in pandemic situations, focusing on facial pose
analysis.
o Convolution Neural Network can help evaluate all features.
o A new method to solve the multiple head crucial problem with
masks during the COVID-19 pandemic is proposed.
o The method is comfortable compared to other methods, and it can
help study multi-angle problems.
o A face detection algorithm can differentiate between wearing a
mask or not.
APPENDIX
CODE
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Conv2D, MaxPooling2D, Dropout, Flatten,
Dense
from tensorflow.keras.optimizers import Adam
from tensorflow.keras.preprocessing.image import ImageDataGenerator
import numpy as np
import tensorflow as tf
import matplotlib.pyplot as plt

import os
os.environ['KAGGLE_USERNAME']='taarusshwadhwa'
os.environ['KAGGLE_KEY']='f2ef5c63de2d4d9d7d2f5b93735d0395'

! kaggle datasets download -d prithwirajmitra/covid-face-mask-detection-


dataset

! unzip covid-face-mask-detection-dataset.zip

main_dir = '/content/New Masks Dataset'


train_dir = os.path.join(main_dir,'Train')
test_dir = os.path.join(main_dir,'Test')
validation_dir = os.path.join(main_dir,'Validation')

train_mask_dir = os.path.join(train_dir, 'Mask')


train_nomask_dir = os.path.join(train_dir, 'Non
Mask')

train_mask_names = os.listdir(train_mask_dir)
print(train_mask_names[:10])

train_nomask_names = os.listdir(train_nomask_dir)
print(train_nomask_names[:10])

import matplotlib.image as
mpimg nrows = 4
ncols = 4
plt.figure(figsize=(12,12))

mask_pic=[]
for i in train_mask_names[0:8]:
mask_pic.append(os.path.join(train_mask_dir,i))

nomask_pic=[]
for i in train_nomask_names[0:8]:
nomask_pic.append(os.path.join(train_nomask_dir,i))

print(mask_pic)
print(nomask_pic)

merged_list = mask_pic + nomask_pic

for i in range(0, len(merged_list)):


data = merged_list[i].split('/', 4)[4]
sp = plt.subplot(nrows, ncols, i+1)
sp.axis('Off')
image = mpimg.imread(merged_list[i])
sp.set_title(data, fontsize=8)
plt.imshow(image,
cmap='Blues')

train_datagen = ImageDataGenerator(rescale=1./255,
zoom_range = 0.2,
rotation_range = 40,
horizontal_flip = True
)

val_datagen = ImageDataGenerator(rescale = 1./255)


test_datagen = ImageDataGenerator(rescale=1./255)

train_generator = train_datagen.flow_from_directory(train_dir,
target_size=(150,150),
batch_size=32,
class_mode='binary'
)

val_generator = val_datagen.flow_from_directory(validation_dir,
target_size=(150,150),
batch_size=32,
class_mode='binary'
)

test_generator = test_datagen.flow_from_directory(test_dir,
target_size=(150,150),
batch_size=32,
class_mode='binary'
)
model = Sequential()
model.add(Conv2D(32, (3,3), padding='SAME',
activation='relu', input_shape=(150,150,3)))
model.add(MaxPooling2D(pool_size=(2,2)))
model.add(Dropout(0.5))
model.add(Conv2D(64, (3,3), padding='SAME',
activation='relu')) model.add(MaxPooling2D(pool_size=(2,2)))
model.add(Dropout(0.5))
model.add(Flatten())
model.add(Dense(256,
activation='relu'))
model.add(Dropout(0.5))

model.summary()

model.compile(Adam(lr=0.001), loss='binary_crossentropy',
metrics=['accuracy'])

history = model.fit(train_generator,
epochs = 30,
validation_data = val_generator)

history.history.keys()

plt.plot(history.history['loss'])
plt.plot(history.history['val_loss'])
plt.legend(['Training', 'Validation'])
plt.title('Training and Validation Loss')
plt.xlabel('epoch')

plt.plot(history.history['accuracy'])
plt.plot(history.history['val_accuracy'])
plt.legend(['Training', 'Validation'])
plt.title('Training and Validation Accuracy')
plt.xlabel('epoch')

test_loss, test_accuracy = model.evaluate(test_generator)


print('test loss:{} test accuracy:{}'.format(test_loss, test_accuracy))

from google.colab import files


from keras.preprocessing import image
uploaded = files.upload()
for fname in uploaded.keys():
img_path =
'/content/'+fname
img = tf.keras.utils.load_img(img_path, target_size=(150,150))
images = tf.keras.utils.img_to_array(img)
images = np.expand_dims(images, axis=0)
prediction = model.predict(images)
print(fname)
if prediction==0:
print('Mask!')
else:

model.save('model.h5')
import cv2
import tensorflow as tf
from tensorflow.keras.models import load_model
#from tf.keras.preprocessing.image import load_img , img_to_array
from google.colab.patches import cv2_imshow
import numpy as np

model =load_model('/content/model.h5')

img_width , img_height =

150,150 face_cascade =
cv2.CascadeClassifier('/content/haarcascade_frontalface_default.xml')

cap = cv2.VideoCapture('/content/video.mp4')

img_count_full = 0

font = cv2.FONT_HERSHEY_SIMPLEX
org = (1,1)
class_label = ''
fontScale = 1
color = (255,0,0)
thickness = 2

while True:
img_count_full += 1
response , color_img = cap.read()

if response == False:
break

scale = 50
width = int(color_img.shape[1]*scale /100)
height = int(color_img.shape[0]*scale/100) dim =
(width,height)

color_img = cv2.resize(color_img, dim ,interpolation= cv2.INTER_AREA)

gray_img = cv2.cvtColor(color_img,cv2.COLOR_BGR2GRAY)

faces = face_cascade.detectMultiScale(gray_img, 1.1, 6)

img_count = 0
for (x,y,w,h) in faces: org = (x-
10,y-10) img_count += 1
color_face = color_img[y:y+h,x:x+w] cv2.imwrite('/content/Detected_Faces/%d%dface.jpg'%
(img_count_full,img
_count),color_face)
img = tf.keras.utils.load_img('/content/Detected_Faces/%d%dface.jpg'%(img_count_full
,img_count),target_size=(img_width,img_height)) img =
tf.keras.utils.img_to_array(img) img =
np.expand_dims(img,axis=0) prediction =
model.predict(img)
if prediction==0: class_label =
"Mask" color = (255,0,0)

else:
class_label = "No Mask" color
= (0,255,0)

cv2.rectangle(color_img,(x,y),(x+w,y+h),(0,0,255),3) cv2.putText(color_img, class_label, org,


font ,fontScale, color,
thickness,cv2.LINE_AA)

cv2_imshow(color_img)
if cv2.waitKey(1) & 0xFF == ord('q'): break

cap.release()
cv2.destroyAllWindows()
RESULTS GIVING INPUT AS VIDEO:
RESULTS GIVING INPUT AS IMAGE:
CONCLUSION

This manuscript proposes a face mask recognition system for static images and
real-time video that automatically identifies if a person is wearing a mask (see
Fig. 10), which is an excellent solution for deterring the spread of the COVID-
19 pandemic. By using Keras, OpenCV, and CNN, the proposed system can
detect the presence or absence of a face mask and the model
gives precise and quick results. The trained model yields an accuracy of
around 98%. Trials were conducted to compare it with other pre-existing
popular models which demonstrates that the proposed model performs better
than DenseNet-121, MobileNet-V2, VGG-19, and Inception-V3 in terms of
processing time and accuracy. This methodology is an excellent contender
for a real-time monitoring system because of its precision and computing
efficiency.
REFERENCES

 https://doi.org/10.1007/978-3-319-46454-1_8
 https://doi.org/10.1109/JSEN.2021.3061178
 https://doi.org/10.1109/CVPR.2016.90
 https://doi.org/10.3390/s20071974

You might also like