0% found this document useful (0 votes)
28 views36 pages

Final.r1222eportt Facemask

Repot

Uploaded by

takiaadhi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views36 pages

Final.r1222eportt Facemask

Repot

Uploaded by

takiaadhi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 36

+ FACE MASK DETECTION USING CNN

A PROJECT REPORT

Submitted by

SUBASH.R [613521104046]

SHENJIN S A SOLOMON [613521104043]

ARUN.R [613521104702]

In partial fulfilment for the award of the degree

of

BACHELOR OF ENGINEERING

in

COMPUTER SCIENCE AND ENGINEERING

GOVERNMENT COLLEGE OF ENGINEERING, DHARMAPURI

ANNA UNIVERSITY: CHENNAI 600 025

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

Mrs.P.Sugavanaeshwari M.E., Mrs.P.Sugavanaeshwari M.E.,

Head of The Department, Supervisor,

Department of Computer Science and Department of Computer Science and


Engineering , Engineering ,

Government College of Engineering, Government College of Engineering,


Dharmapuri. Dharmapuri.

Submitted for the university examination held at Government College of


Engineering, Dharmapuri on ……………..

INTERNAL EXAMINER EXTERNAL EXAMINER

ii
ACKNOWLEDGEMENT

We are personally indebted to a number of people who gave us their


useful insights to aid in our overall progress for this project. A complete
acknowledgement would therefore be encyclopedic. First of all, we would like
to give our deepest gratitude to our parents for permitting us to take up this
course.

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

CHAPTER NO TITLE PAGE NO

ABSTARCT vii

LIST OF FIGURES viii

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

5.2 Importing necessary


libraries......................................27

5.3 Creating Labels for the two class of


Images................27
5.3.1 Collect Data.................................................28
5.3.2 Create Labels for Each
Class........................28
5.3.3 Combine the Labels.....................................28
5.3.4 Verify the
Labels..........................................28
5.3.5 Codings........................................................29
5.3.6 Explanation...................................................29
5.4 Image Processing.........................................................30
5.4.1 Steps for Image
Processing...........................30
5.5 Train Test Split............................................................34
5.6 Building a Convolutional Neural Networks (CNN)....35
5.7 Model Evaluation and Visualization...........................38
5.8 Building a Predictive System for Face Mask Detection…40
6 CONCLUSION................................................................................44

7 REFERENCES……………………………………………….……45

v
ABSTRACT

The project involves the creation of a dataset comprising images


of people with and without face masks. The dataset is preprocessed and
augmented to enhance the model's robustness and generalization capabilities.
The CNN model architecture is then constructed and trained on this dataset.
Various techniques, such as dropout, batch normalization, and data
augmentation, are employed to improve the model's performance and reduce
overfitting.

The trained model is evaluated using standard metrics such as


accuracy, precision, recall, and F1-score. The results demonstrate that the CNN-
based face mask detection system achieves high accuracy and reliability in
differentiating between masked and unmasked faces.

This system can be integrated into various applications, including


surveillance systems, entry-point security checks, and public transportation
monitoring, to ensure compliance with mask-wearing regulations and enhance
public health safety. The project highlights the potential of deep learning and
CNNs in addressing critical real-world challenges during a pandemic.

vi
LIST OF FIGURES

FIGURE NO. FIGURE NAME

1 Biological neuron

2 Artificial neuron

3 Layered neural network

4 CNN architecture

5 Convolutional layers

6 Tensor’s architecture

7 Syproject path

8 Host connection

9 Image without mask

10 Image with mask

11 Importing the dependencies

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

The primary objective of this project is to develop a highly accurate


and efficient face mask detection system using Convolutional Neural Networks
(CNNs). The need for automated and reliable systems to monitor and enforce
mask-wearing protocols has become critical. The specific goals of this project
are as follows:

1. Data Collection and Preparation: Compile a comprehensive dataset of


images featuring individuals with and without face masks. This dataset
will be carefully annotated and preprocessed to ensure high-quality input
for the CNN model.
2. Model Development: Design and implement a robust CNN architecture
tailored for the task of face mask detection. The model will be trained to
distinguish between masked and unmasked faces with high accuracy.
3. Performance Optimization: Apply advanced techniques such as data
augmentation, dropout, and batch normalization to enhance the model's
performance and generalization capabilities. The aim is to achieve
optimal accuracy while minimizing the risk of overfitting.
4. Real-Time Detection: Ensure that the system can operate in real-time,
making it suitable for integration into various practical applications,
including surveillance systems, entry-point security, and public
transportation monitoring.
5. Evaluation and Validation: Conduct thorough testing and validation of
the model using standard evaluation metrics such as accuracy and

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.

The system is designed for deployment in various public and private


sectors, including public safety and health monitoring in airports, schools, and
transportation systems, as well as workplace safety and healthcare facilities.
Future enhancements include extending detection capabilities to other PPE,
improving model accuracy with new data, developing scalable solutions for
high-resolution and large-scale deployments, and offering user customization
options for specific needs and environments.

2
CHAPTER 2

SYSTEM REQUIREMENTS

2.1 Hardware Requirements:

1.Webcam:

1. A functional webcam is necessary for capturing real-time


video streams.
2. Ensure your system has a working webcam.

2.System Resources:

1. At least 4 GB RAM (more is preferable) for smooth


execution.
2. Adequate storage space (e.g., 1TB hard disk).
3. A 64-bit processor (e.g., Intel Core i5 or equivalent).

3. Operating System:

The software components mentioned above are compatible with


various operating systems (Windows, Linux, macOS).

4. Power Supply:

Ensure a stable power supply to avoid interruptions during model


training or inference.

3
2.2 Software Requirements:

1. Python

Python is a versatile and powerful programming language widely used


in machine learning and data science. In this project, Python will be used to
implement the Convolutional Neural Network (CNN) model, handle image
data, preprocess datasets, and visualize results.

2. Google Colab

Google Colab (short for Colaboratory) is a free, cloud-based Jupyter


notebook environment provided by Google. It is particularly useful for machine
learning projects because it offers access to powerful computing resources,
including GPUs, at no cost.

4
CHAPTER 3
SYESTEM DESIGN

3.1 SYSTEM ARCHITECTURE :

A Face Mask Detection model is the subject of this project. A


model has been developed to determine whether people are wearing masks. The
primary camera on the computer was used in this system, and the video was
sent as input to the model that was deployed. This system is built using
OpenCV libraries, as well as images that are supplied into the system during the
learning process. The system was identified using the MobileNet algorithm.
FIGURE 11 shows the overall system design.

FIGURE 1. System architecture

5
3.2 USE CASE DIAGRAM:

A use case diagram in the Unified Modelling Language (UML) can


summarize the details of a system's users (also known as actors) and their
interactions with it. A collection of specialized symbols and connectors to
construct one.

FIGURE 2. Use case diagram

3.3 SEQUENCE DIAGRAM:

A sequence diagram, also known as an event diagram, is a type of


interaction diagram that depicts how different processes interact with one
another and in what order. It's a message-sequence-based chat construct.

6
FIGURE 3. Sequence diagram

3.4 ACTIVITY DIAGRAM:

Activity diagrams are graphical representations of workflows of


stepwise activities and actions with support for choice, iteration and
concurrency. In the Unified Modeling Language, activity diagrams can be used
to describe the business and operational step-by-step workflows of components
in a system. An activity diagram shows the overall flow of control.

7
FIGURE 4. Sequence diagram

8
CHAPTER 4
SYSTEM IMPLEMENTATION

4.1 MODULES:
4.1.1 TensorFlow

TensorFlow is an open-source machine learning software that


focuses on deep neural networks from start to finish. TensorFlow is a collection
of libraries, tools, and community resources that are diverse and comprehensive.
It enables programmers to construct and deploy cutting-edge machine learning
based applications.The shape represents dimensionality. A one-dimensional
tensor is a vector; a two-dimensional tensor is matrix; and a zero-dimensional
tensor is a scalar. Figure 10 shows various tensor dimensions.

FIGURE 5. Tensor’s architecture

9
4.1.2 Keras

Google developed Keras, a high-level deep learning API for building


neural networks. It is written in python and helps with neural network
development. It is modular, quick, and simple to use. It was created by Google
developer Francois Chollet. Low-level computation is not handled by Keras.
Instead, it makes use of a library known as the “Backend. It gives users
complete control and flexibility over their applications, as well as the ability to
quickly implement ideas.

4.1.3 NumPy

NumPy is the most important python package for scientific


computing. It is a library that includes a multidimensional array object, derived
objects (such as masked arrays and matrices), and a variety of routines for
performing fast array operations, such as mathematical, logical, shape
manipulation, sorting, selecting, basic linear algebra, basic statistical operations,
random simulation, and more.

4.1.4 Matplotlib

Matplotlib is an important python visualization library for 2D


array plots. Matplotlib is a multi-platform data visualization package based on
numpy arrays and intended to operate with scipy stack.

10
4.2 CONVOLUTIONAL NEURAL NETWORK(CNN)

Artificial neural networks are becoming increasingly used for


processing unstructured data, such as images, text, audio, and speech. For such
unstructured input, convolutional neural networks (CNNs) operate well.
Convolutional neural networks find essential features from data when there is a
topology connected with it. CNNs are inspired by multi-layer perceptron’s in
terms of architecture.

4.2.1 CNN architectures

CNN architectures occur in a variety of shapes and sizes, but they


all have convolutional and pooling (or subsampling) layers that are organised
into modules. These modules are followed by one or more fully connected
layers, like a normal feedforward neural network. To create a deep model,
modules are frequently stacked on top of one another. The network receives an
image directly, which is then processed through various rounds of convolution
and pooling. The output layer receives the inputs from the layers above it,
executes the calculations using its neurons, and then computes the output.

11
FIGURE 6. CNN architecture
4.2.2 Convolutional layer

The convolutional layer is the most important component of a


CNN because it is where most of the computation takes place. It requires input
data, a filter, and a feature map, among other things.

FIGURE 7. Visual representation of a convolutional layers.

4.2.3 Pooling layer

Downsampling, often known as pooling layers, is a dimensionality


reduction technique that reduces the number of factors in an input. The pooling
process, like the convolutional layer, sweeps a filter across the entire input, but
this filter has no weights. Instead, the kernel populates the output array by
applying an aggregation function to the values in the receptive field.

4.2.4 Fully connected layer


12
This layer performs categorization based on the features extracted by
the preceding layers and the filters applied to them. While convolutional and
pooling layers typically utilize relu functions to classify inputs, fully connected
layers typically use a softmax activation function to produce a probability
ranging from 0 to 1.

4.3 IMPLEMENTATION

This project was completed using google colab . Face mask


detection folder was created as a project folder. Inside the google colab, an
environment with a file named main.py was generated. Within the project, two
folders have been created like dataset and Face Mask project. In the dataset
folder, two Image datasets have been created and are ready to be used for mask
training. Two new files have been added to the face mask project:
train_mask.py and detect_mask.py.

FIGURE 8. Project path

4.3.1 Preparing dataset

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.

FIGURE 9. Images without mask

14
FIGURE 10. Images with mask

4.4 Importing necessary libraries

The python programming language, as well as machine learning


and deep learning methods were used to identify the face masks. Inside the
project path, several required libraries were installed. Libraries were installed
using the cmd-command prompt. Packages like tensorflow, numpy, keras and
matplotlib were imported after the installation.

15
FIGURE 11. Importing the Dependencies

4.4.1 Creating Labels for the two class of Images:

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.

4.4.2 Collect Data:

Assume two sets of images: 3725 images of people "with mask" and
3828 images of people "without mask".

4.4.3 Create Labels for Each Class:

 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.

4.4.4 Combine the Labels:

Concatenate the two lists to create a single list of labels that corresponds
to entire dataset.

4.4.5 Verify the Labels:

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

4.5 Image Processing:

To process images for a face mask detection project,it is necessary to


resize the images, convert them to numpy arrays, and prepare the data and
labels for training a machine learning model.

4.5.1 Steps for Image Processing:

Load Image Paths:

 Assume two directories: one for images with masks (with_mask_path)


and another for images without masks (without_mask_path).
 Lists with_mask_files and without_mask_files contain the filenames of
images in these directories.

17
FIGURE 13. Convert images to numpy arrays

4.6 Train-Test Split and Data Scaling:

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.

FIGURE 14. Train test size

Verify Shapes:
18
Print the shapes of the original dataset and the training and testing sets to ensure
the split is done correctly.

FIGURE 15. Train test shape

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.

FIGURE 16. Scaling the data

Verify Scaling:

Compare the values of an image before and after scaling to ensure the scaling is
done correctly.

FIGURE 17. Verify the scaling data

19
4.7 Building a Convolutional Neural Networks (CNN):

Building a Convolutional Neural Network (CNN) for face mask detection


involves several steps. Here’s a concise explanation:

4.7.1 Import Necessary Libraries:

First, import TensorFlow and Keras, which are essential for building and
training the CNN.

FIGURE 18. Importing Libraries

4.7.2 Define the Model:

Create a Sequential model and add convolutional, pooling, and activation


layers.

First Convolutional Layer:

 Conv2D with 32 filters, kernel size of (3,3), and ReLU activation.


 Input shape specified as (128,128,3) for 128x128 RGB images.
 MaxPooling2D with pool size of (2,2) to reduce spatial dimensions.

Second Convolutional Layer:

 Conv2D with 64 filters, kernel size of (3,3), and ReLU activation.


 MaxPooling2D with pool size of (2,2).

20
FIGURE 19. Defining the model

4.7.3 Compile the Model:

Compile the neural network with the Adam optimizer, sparse categorical cross-
entropy loss function, and accuracy as the evaluation metric.

FIGURE 20. Compiling the modes

4.7.4 Train the Model:


Train the CNN using the fit method. Use the scaled training data
(X_train_scaled and Y_train), set aside 10% of the training data for validation,
and train for 5 epochs.

21
4.7.5 Training Output:

During training, the model’s performance is evaluated after each epoch,


displaying the training loss, accuracy, validation loss, and validation accuracy.

FIGURE 21. Trained output

4.8 Model Evaluation and Visualization:

4.8.1 Evaluate the Model:

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.

FIGURE 22. Model Evaluation

4.8.2 Visualization of Training Process:

22
Visualizing the training and validation loss and accuracy helps understand how
well the model is learning and if it’s overfitting or underfitting.

FIGURE 23. Visualization Process

23
FIGURE 24. Loss and Accuracy

4.9 Building a Predictive System for Face Mask Detection:

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:

4.9.1 Loading and Displaying the Input Image:

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.

4.9.3 Making Predictions:

Use the trained model to predict the class of the input image.

4.9.4 Interpreting the Prediction:

Convert the prediction probabilities into a class label.

4.9.5 Displaying the Result:

Based on the predicted label, display whether the person in the image is wearing
a mask.

FIGURE 25. Result Process

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:

Developing a convolutional neural network (CNN) for face mask detection is


crucial for public health efforts. Trained on 12,000 mask images, the model
achieved impressive accuracy during both training and testing. Its exceptional
precision, recall, and F1 score contribute significantly to disease prevention,
particularly during the COVID-19 pandemic.

27
7.REFERENCES

[1]Francois Chollet, “Deep Learning with Python”, Second Edition, Manning


Publication,2021.

[2]Ian Goodfellow, Yoshua Bengio, Aaron Courville, ”Deep Learning” MIT


Press,2016.

28

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy