Final.r1222eportt Facemask
Final.r1222eportt Facemask
A PROJECT REPORT
Submitted by
SUBASH.R [613521104046]
ARUN.R [613521104702]
of
BACHELOR OF ENGINEERING
in
JUNE 2024
i
BONAFIDE CERTIFICATE
Certified that this project report “FACE MASK DETECTION USING CNN”
is the bonafide work of the following students, SHENJIN S A SOLOMON
[613521104043], SUBASH R [613521104048], ARUN R
[613521104702] ,who carried out the project work under my supervision.
SIGNATURE SIGNATURE
ii
ACKNOWLEDGEMENT
We feel happy to convey our kind regards and sincere thanks to our
beloved Principal Dr.SUMATHI, M.E, Ph.D. who provided her kind concern
for carrying out this project work and providing suitable environment to work
with.
We wish to express our sense of gratitude and sincere thanks to our Head
of the Department Mrs. P.SUGAVANAESHWARI, M.E., of Computer
Science and Engineering for her valuable guidance in the preparation and
presentation of this project.
We specially thank our project Supervisor Mrs.
P.SUGAVANAESHWARI M.E., Assistant Professor, of Computer Science
and Engineering for her valuable guidance in preparation and presentation of
the project.
We thank all our Friends, Teaching, Non-Teaching staffs and our well-
wishers for their constant support all the time.
iii
TABLE OF CONTENTS
ABSTARCT vii
LIST OF ABBREVIATIONS ix
1 INTRODUCTION…………………………………………....1
2 DEEP LEARNING………………………………………..….2
2.1 Artificial neural networks & biological brains..2
2.2 The process of deep learning………………….4
2.3 Deep learning meth……………………………7
2.4 Examples of deep learning at work ………… .7
3 CONVOLUTIONAL NEURALNETWORK(CNN)...……….7
3.1 CNN architectures...............................................8
3.2 Workflow of CNN ..............................................9
3.2.1 Convolutional layer..................................9
3.2.2 Pooling layer...........................................11
3.2.3 Fully connected layer..............................12
3.3 Different architectures in CNN............................12
3.3.1 LetNet......................................................13
3.3.2 ZFNet .....................................................14
3.3.3 VGGNet .................................................15
3.3.4 MobileNets.............................................16
4 RELATED TECHNOLOGY ..................................................17
4.1 Python.................................................................18
4.2 TensorFlow ........................................................19
4.3 Keras...................................................................20
4.4 OpenCV-python ................................................21
iv
4.5 NumPy and SciPy.................................................21
4.6 Imutils and Matplotlib..........................................21
5 IMPLEMENTATION OF
PROBLEM................................................22
5.1 Preparing
dataset........................................................22
7 REFERENCES……………………………………………….……45
v
ABSTRACT
vi
LIST OF FIGURES
1 Biological neuron
2 Artificial neuron
4 CNN architecture
5 Convolutional layers
6 Tensor’s architecture
7 Syproject path
8 Host connection
CONCEPT DEFINITIONS:
vii
List of Abbreviations:
AI Artificial Intelligence
CV Computer Vision
ML Machine Learning
OpenCV Open-Source Computer Vision Library
Accuracy Percentage of correct classified images
Matrix Multi-dimensional
Optimizer A function used to compute gradient
Relu Rectifiled linear unit
Scalar Single value
Softmax Activation function
Test data Data that the network has not seen
Training data Data used for training
CNN Convolutional neural network
OS Operating System
NP NumPy
Flatten A Utility layer
Validation data Data used for validating algorithm
LB Labels
Split Data dividation
DNN Deep neural network
Locs Location
PREDS Prediction
RGB Red Green Blue
viii
CHAPTER 1
INTRODUCTION
1.1 Objective
1
precision.The objective is to demonstrate the system's reliability and
effectiveness in real-world scenarios.
6. Deployment: Explore potential deployment strategies for integrating the
face mask detection system into existing infrastructure, thereby
contributing to public health safety and compliance with mask-wearing
regulations.
1.2 Scope
The scope of the face mask detection using CNN project encompasses
developing a robust and accurate Convolutional Neural Network to classify
images into "Mask" and "No Mask" categories. The project involves extensive
data collection, preprocessing, and model training using Python libraries like
TensorFlow, Keras, followed by rigorous evaluation through metrics such as
accuracy and precision.
2
CHAPTER 2
SYSTEM REQUIREMENTS
1.Webcam:
2.System Resources:
3. Operating System:
4. Power Supply:
3
2.2 Software Requirements:
1. Python
2. Google Colab
4
CHAPTER 3
SYESTEM DESIGN
5
3.2 USE CASE DIAGRAM:
6
FIGURE 3. Sequence diagram
7
FIGURE 4. Sequence diagram
8
CHAPTER 4
SYSTEM IMPLEMENTATION
4.1 MODULES:
4.1.1 TensorFlow
9
4.1.2 Keras
4.1.3 NumPy
4.1.4 Matplotlib
10
4.2 CONVOLUTIONAL NEURAL NETWORK(CNN)
11
FIGURE 6. CNN architecture
4.2.2 Convolutional layer
4.3 IMPLEMENTATION
13
Two image datasets were collected from the kaggle website for the
model’s training and testing purposes (Kaggle 2022.) Following that, image
dataset was split into two groups: one Images_with_mask and one Images_
without_mask. More images have also been added to the dataset, which were
taken with the laptop’s default camera. Using these datasets, it is possible to
develop a model that can distinguish between people wearing masks and people
who are not wearing masks.
14
FIGURE 10. Images with mask
15
FIGURE 11. Importing the Dependencies
To create labels for a face mask detection dataset, you will assign
numerical values to each class: "with mask" as 1 and "without mask" as 0.
Assume two sets of images: 3725 images of people "with mask" and
3828 images of people "without mask".
For the "with mask" images, create a list where each element is 1.
For the "without mask" images, create a list where each element is 0.
Concatenate the two lists to create a single list of labels that corresponds
to entire dataset.
Print a few labels from each class and check the total number of labels to
ensure they match the number of images.
16
FIGURE 12. Creating Labels
17
FIGURE 13. Convert images to numpy arrays
Train-Test Split:
The dataset X (image data) and Y (labels) is split into training and testing
sets using the train_test_split function from sklearn.model_selection.
The split is performed with 80% of the data used for training and 20% for
testing (test_size=0.2).
The random_state=2 parameter ensures the split is reproducible.
Verify Shapes:
18
Print the shapes of the original dataset and the training and testing sets to ensure
the split is done correctly.
Data Scaling:
Image pixel values range from 0 to 255. Scaling these values to a range of
0 to 1 can improve model performance and training stability.
This is done by dividing the pixel values by 255.
Verify Scaling:
Compare the values of an image before and after scaling to ensure the scaling is
done correctly.
19
4.7 Building a Convolutional Neural Networks (CNN):
First, import TensorFlow and Keras, which are essential for building and
training the CNN.
20
FIGURE 19. Defining the model
Compile the neural network with the Adam optimizer, sparse categorical cross-
entropy loss function, and accuracy as the evaluation metric.
21
4.7.5 Training Output:
Evaluate the trained model on the test dataset to determine its accuracy and loss.
This step gives an unbiased estimate of the model's performance on unseen data.
22
Visualizing the training and validation loss and accuracy helps understand how
well the model is learning and if it’s overfitting or underfitting.
23
FIGURE 24. Loss and Accuracy
A predictive system uses a trained model to classify new images as either "with
mask" or "without mask". Here’s a detailed explanation of the steps involved:
First, prompt the user to input the path of the image to be predicted. Use
OpenCV to read and display the image.
24
4.9.2 Preprocessing the Input Image:
Resize, scale, and reshape the image to match the input shape expected by the
CNN model.
Use the trained model to predict the class of the input image.
Based on the predicted label, display whether the person in the image is wearing
a mask.
25
FIGURE 26. Result Output
This process makes it easy to use the trained CNN model to classify new images
for face mask detection, providing immediate feedback on the presence or
absence of a mask.
26
CONCLUSION:
27
7.REFERENCES
28