Face Mask Detection Using Python
Face Mask Detection Using Python
1 – Introduction
The coronavirus COVID-19 pandemic is triggering a worldwide
health catastrophe, hence the World Health Organization
recommends wearing a face mask in designated areas. Face
Mask Detection and Hand Sanitization have been a well-known
subject in recent times, as well as in image preparation and
computer vision. Many new computations are being devised that
use convolutional architectures to make the computation as
exact as possible. These convolutional architectures have made
it possible to extract even pixel nuances. I propose to design a
dual face classifier that can recognize every face in the edge,
independent of its arrangement. We offer a method for
generating precise face division veils from any subjectively sized
input image. Preparation is carried out using Fully Convolutional
Networks to semantically segment out the faces in the image.
This is accomplished by adding a microprocessor such as the
Raspberry Pi 3 Model B, a Pi-camera, a Relay, an Infrared Non-
contact Temperature sensor, and other sensors, and thereafter
developing a model by connecting each of these components.
DECLARATION
We hereby declare that this submission is our own work and that, to the best of our knowledge and
belief, it contain no matter previously published or written by another person nor material
substantial extent has been accepted for the award of any other degree or diploma of the university
or other institute of higher learning, except where due acknowledgment has been made in the text.
Date: (04/01/2025)
2– Flowchart
3 – Methodology
Methodology: Face Mask Detection Using Python
The methodology for developing a face mask detection system using Python involves a
systematic approach, combining image processing, machine learning, and computer vision
techniques. The process begins with data collection, where a dataset comprising images of
people with and without face masks is gathered. The dataset is then preprocessed, including
resizing images, normalizing pixel values, and performing data augmentation to enhance
model robustness.
Next, feature extraction is carried out using a deep learning-based approach. Pretrained
convolutional neural networks (CNNs), such as MobileNetV2 or ResNet, are employed to
extract high-level features from the images. Transfer learning is applied by fine-tuning these
models on the face mask dataset, reducing training time while improving accuracy.
The core of the project is model training. The dataset is divided into training, validation, and
test sets, and the model is trained using a suitable optimizer (e.g., Adam) and a categorical
cross-entropy loss function. Key metrics such as accuracy, precision, recall, and F1-score are
monitored to evaluate performance.
Finally, the trained model is integrated with a real-time face detection system using OpenCV.
This allows for real-time face mask detection through a webcam. Extensive testing is
conducted to ensure reliable detection across diverse conditions, including varying lighting,
angles, and face orientations.
This methodology ensures a scalable, accurate, and efficient face mask detection system.
4 – Python
Python is a high-level, object-oriented, and interpreted programming language. It was created
by Guido van Rossum from 1985 to 1990 and released in 1991.
Python's syntax is close to the English language, allowing developers to construct programs
with fewer lines than some other programming languages. Python is an interpreter-based
language, which means that code can be executed as soon as it is written. Prototyping may be
done quickly.
Characteristics of Python :-
Features of python:-
WHY PYTHON?
Python is an excellent cross- platform language and it works on different platforms
(Windows, Mac, Linux, UNIX, Raspberry Pi, and so on).
Python has a simple syntax similar to the English language.
Python has syntax similar to English language that allows developers to write programs
with fewer lines than some other programming languages.
Python can be treated in a procedural way, an object-oriented way or a functional way.
Python runs on an interpreter system, meaning that code can be executed as soon as
written. This means that proto-typing can be very quick.
The formation of python syntax is simple and straight forward which also makes it
popular.
Python codes can be run on a wide variety of hardware platforms having the same
interface.
Python is a preferred high-level, server-side programming language for websites and
mobile apps.
For both, new and old developers, Python has managed to stay a language of choice with
ease.
Python is also foraying into Big Data in a significant way.
Use of NumPy : -
NumPy is a Python package. It means 'Numerical Python'. It is a library that includes
multidimensional array objects as well as routines for array processing.
Jim Hugunin created Numeric, the predecessor to NumPy. Another package, Num array, was
also created, with some more features.
Travis Oliphant created NumPy in 2005 by adding Num array functionality into the Numeric
library. There are numerous contributors to this open source project.
Operations with NumPy NumPy allows developers to conduct logical and mathematical
operations on arrays, as well as Fourier transformations and shape manipulation methods.
1. LISTS -
• Ordered collection of data or sequence of values.
• List is also a sequence type— Sequence operations are applicable
• Supports similar slicing and indexing functionalities as in the case of strings.
• They are mutable.
• Advantages of a list over a conventional array.
• List have no size or type constraints (no setting restrictions beforehand)
• They can contain different object types.
• Example-
my_list = [‘one’, ’two’, ‘three’, 4, 5]
len(my_list) would output 5.
2. DICTIONARY-
• Lists are sequences but the dictionaries are mappings.
• They are mapping between a unique key and a value pair.
• Each key is separated from its value by a colon (:), the items are separated by
commas, and the whole thing is enclosed in curly braces.
• These mappings may not retain order.
• Constructing the dictionary.
• Accessing object from the dictionary.
• Nesting Dictionaries.
• Basic Dictionary Methods.
• Basic syntax
d = {} empty dictionary will be generated and assign keys and values to it, like
d [‘animal’] = ‘Dog’
d = (‘k1’, ‘v1’, ‘k2’, ‘v2’}
d [‘k1’] outputs ‘v1’
3. TUPLES-
• A tuple is a sequence of immutable python objects.
• Tuples are sequences, just like lists.
• The difference between tuples ad lists are, the tuples cannot be changed unlike lists
and tuples use parentheses, whereas lists use square brackets.
• Immutable in nature, i.e. they cannot be changed.
• No type restriction
• Indexing and slicing, everything's same like that in strings and lists.
• Constructing tuples.
• Basic tuple methods:- immutability.
• We can use tuples to present things that shouldn’t change, such as days of the week,
or dates on a calendar, etc.
• We can delete elements from a list by using Del list_name [index_val].
4. SETS-
• A set contains unique and unordered elements and we can construct them by using a
set() function.
• Convert a list into Set- l=[1,2,3,4,1,1,2,3,6,7]
• k = set(l) k becomes {1,2,3,4,6,7}
• Basic Syntax-
• x=set()
• x.add(1)
• x = {1}
• x.add(1)
• This would make no change in x now.
1. if-else statements:
An if statement can be followed by an optional else statement, which executes when the
Boolean expression is False.
Example:-
x=8
r=x%2
if r== 0:
Print(“Even”)
else:
Print(“Odd”)
2-nested-if statements:
An nested-if statements can use one if or else if statement inside another if or else
statement (can be followed by many optional if or else statement)
Example:-
x=8
r=x%2
if r==0:
print(“Even”)
if x > 5:
print(“Great”)
else :
print(“Not so great!”)
else :
print(“odd”)
Python – Strings
Strings are amongst the most popular types in python. We can create them simply by
enclosing characters in quotes. Python treats single quotes the same as double quotes.
Creating strings is as simple as assigning a value to a variable.
For example –
var1 = “Hello World!”
var2 = “Python Programming”
Indexing-
Strings can be indexed.
First character has index 0.
Negative indices start counting from the right.
Negative indices start from -1.
-1 means last, -2 means second last, and so on.
Slicing-
To obtain a substring
s [start – end] means substring of s starting at index start and ending at index end -1.
s [0:len(s)] is same as s.
Both start and end are optional -
— If start is omitted, it defaults to 0.
— If end is omitted, it defaults to the length of string.
S[:] is same as s[0: len(s)] – Essentially, a copy of s.
Use of Pandas : -
Pandas is an open-source Python library licensed under BSD that provides high-performance,
user-friendly data structures and data analysis tools for the Python programming language.
Python with Pandas is utilized in a variety of sectors, both academic and commercial, such as
finance, economics, statistics, and analytics.
Pandas is an open-source Python library that offers high-performance data manipulation and
analysis tools through its strong data structures. Pandas is named after Panel Data, a type of
econometrics that uses multidimensional data.
1 – Series
2 – Data Frame
3 – Panel
These data structure are built on top of NumPy array , which means they are fast .
Use of Plotly: -
Plotly is another great Python module for building interactive and publishable visuals. It
supports a wide range of chart types and customization possibilities, making it ideal for
building interactive dashboards, online apps, and presentations. Here are some of the main
uses and features of Plotly.
Plotly specializes in creating interactive visualizations that allow users to explore data points,
zoom in on specific areas, and reveal extra information when hovered.
Plotly is an open-source Python module for data visualization that supports a variety of
graphs such as line charts, scatter plots, bar charts, histograms, and area plots. Plotly creates
interactive graphs, which can be integrated on websites and offer a wide range of advanced
plotting choices.
1- Plotly specializes in creating interactive visualizations that allow users to explore data
points, zoom in on specific areas, and reveal extra information when hovered.
2- Scatter Plots: Plotly supports scatter plot customisation with markers, colors, sizes,
and tooltips for each data point.
3- Plotly allows you to build interactive bar charts with choices for stacked, grouped,
and horizontal bars, as well as color and annotation customization.
4- Heatmaps: Plotly can create interactive heatmaps to visualize matrix or categorical
data.
5- Dashboard and Layout Customization: Plotly lets you customize dashboard layouts
with many subplots, annotations, and responsive designs.
5-Dataset
Creating a dataset for analyzing employee career surveys requires multiple processes. Here's
an organized technique to generating such a dataset:
1. Define the variables and survey questions.
Employee Information: - ID (anonymous if required)
Please provide your age, gender, department/division, and job title/position.
Years of experience.
Previous companies worked for
Previous positions Education level
2. Data Collection.
Conduct the survey using a platform that supports structured data export (e.g., Google Forms,
SurveyMonkey).
Maintain anonymity and secrecy according to corporate policies.
3. Data preparation.
4. Data Structure
Divide the data into columns (variables) and rows (individual survey replies).
Ensure that each variable has a clear definition and data type.
5. Data Analysis.