Nothing Special   »   [go: up one dir, main page]

Gender Classification Using Opencv: Under The Guidance of

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

Gender Classification using OpenCV

Submitted in partial fulfilment of


requirements for the award of degree of

B. TECH

COMPUTER SCIENCE AND


ENGINEERING

SUBMITTED BY

Saurav Jain ( CSE/17/225)

Under the
Guidance Of

Ms. Gurminder Kaur

Department of Computer Science and


Engineering

B.M. Institute of Engineering and


Technology Sector-10,
Sonipat
(Affiliated to GGSIP University, Delhi)
Certificate

It is to certify that the project has been carried out by the


students of 8th semester Saurav Jain(CSE/17/225) under my
guidance. The report covers all the aspects of the work done
(including H/W & S/W, Coding etc.).
The project report is complete in all respects and I have
understood the entire software.

Ms Gurminder Kaur Mr
Tushar Verma

Guide name Incharge


Name
Certificate

It is to certify that the project has been carried out by the


student of 8th semester
Saurav Jain (CSE/17/225) under the guidance of Computer
Science and Engineering Department. The report covers all the
aspects of the work done (including H/W & S/W, Coding etc.)

Mr Pardeep Tyagi
Name of incharge CSE Department
H.O.D. COMPUTER SCIENCE AND ENGINEERING
DEPARTMENT OF COMPUTER SCIENCE AND
ENGINEERING

(AFFILIATED TO GURU GOBIND SINGH INDRAPRASTHA UNIVERSITY,


DELHI) DELHI –
110089

CANDIDATE’S DECLARATION
It is hereby certified that the work which is being presented in the B. Tech
Major Project Report entitled "Age and Gender Estimator" in partial fulfilment
of the requirements for the award of the degree of Bachelor of Technology
and submitted in the Department of Computer science and engineering ,
B.M.I.E.T (Affiliated to Guru Gobind Singh Indraprastha University, Delhi)
is an authentic record of our own work carried out during a period from
FEB,2021 to JUNE,2021 under the guidance of Ms Gurminder Kaur ,
Associate Professor , CSE
The matter presented in the B. Tech Major Project Report has not been submitted
by me for the award of any other degree of this or any other Institute.

Student name Saurav Jain


Rollno CSE/17/225

This is to certify that the above statement made by the candidate is correct to the
best of my knowledge. They are permitted to appear in the External Major Project
Examination

Guide Name – Ms Gurminder Kaur

The B. Tech Major Project Viva-Voce Examination of Saurav Jain( CSE/17/225)


has been held on ……………………………….

Project Coordinator (Signature of External


Examiner)
ACKNOWLEDGEMENT
We express our deep gratitude to Ms Gurminder Kaur, Department of
computer science and Engineering for his valuable guidance and
suggestion throughout my project work. We are thankful to Mr Pardeep
Tyagi, Project Coordinators, for their valuable guidance.

We would like to extend my sincere thanks to HOD, for his time to time
suggestions to complete my project work. I am also thankful to Dr.HARISH
MITTAL for providing me the facilities to carry out my project work.

Saurav Jain

CSE/17/225
List of Figures
S.NO. NAME P.NO.
1. Methodology 11
2. Residual block 12
3. ResNet50 13
4. Mod1 flow diagram 14
5. Mod2 flow diagram 15
6. Final output 16
7. Final output 17
ABSTRACT

This report describes my minor project that has been done in partial
fulfilment of the requirements for the award of the degree of Bachelor of
Technology. The title of this project is “Age and Gender Estimator”. This
project is basically divided into 2 Modules namely Mod1 and Mod2.
This project report is divided into four different chapters
Chapter 1 includes the problem statement, nee of the study, introduction
and the objective of the project. It also includes the theoretical
explanation about the same.
Chapter2 includes all the necessary introduction to the projects with brief
into about the functionality of Mod1 and Mod2. All the important data flow
diagrams, flow hart related to project is covered in this chapter. Software
and hardware required for this project is also included in this chapter.
Chapter 3 includes experimental result with all the necessary output and
result with screenshots attached. This chapter also included the merit
and demerit of the project and the output obtained from this project.
Chapter 4 includes conclusions and the future scope of this project. All
the future idea that how can this project be extended will be cover in this
chapter. The final conclusion and accuracy of this project is discussed in
this chapter briefly.
CHAPTER 1: INTRODUCTION

1.1 Problem Statement


To ensure the security and privacy of applications in mobile phones, we designed a
Machine Learning Algorithm which will only unlock the application when it will detect
your face and ensure you as the authorized user.

To extend the face recognition system, an age predictor and gender classifier is to be
added.

1.2 Need of the study


As we see in the digital era every personal or important thing is in our mobile
phones or systems. There are many social media applications which is used
for estimating age and genders. Also in automation of forensics we can use
this model to predict age and gender using only a picture of the body.

1.3 Introduction
As technology enhances, the applications that combine the advanced fields of
pattern recognition and image processing are used to find age and gender. In
today's world, age plays a prominent role, when you appear for an interview,
health check-ups.

The information of age is used in many government, private and advertising


sector organization to find the culprits, employee eligible for the job, audience
to be targeted for their publicity of product respectively. However, it's not that
easy to find the age of a person, and there are constraints that restrict us from
seeing the correct age among the set of images. Human face contains lot of
information through their expressions.

These expressions confuse us while finding the age, and as their expression
change, the facial feature differs, resulting in either higher or low than the
people's ideal age. Age estimation is a subfield of face recognition and face
tracking which in combination can predict the health of the individual. Many
health care applications use this mechanism to keep track of health by
monitoring their daily activities.

Gender classification is also a subfield of face that aims to algorithmically


identify the gender of individuals in photographs and videos. Gender also plays
an important role in intelligent applications, such as access control, human-
computer interaction, law enforcement, marketing intelligence and visual
surveillance, etc.

Gender and age are used as biometrics to identify humans uniquely.

To predict the age and gender, we will use a wide range of machine learning
and deep learning algorithms. Neural networks is one of the most used
techniques for age and gender detection. We will use OpenCV library to capture
images, Haar Cascade classifier for face detection and Residual networks for
gender and age estimation.

OpenCV is a collection of software algorithms put together in a library to be


used for computer vision applications.

Haar Cascade is a machine learning-based approach where a lot of positive and


negative images are used to train the classifier. Positive images are those
images which we want our classifier to identify and negative images are the
images which do not contain the object we want to detect.
There are many types of Haar Cascade classifier such as
haarcascade_frontalface_default.xml (for frontal face
detection), haarcascade_eye.xml (for face and eye
detection), haarcascade_car.xml (for vehicle detection from streaming
video), haarcascade_fullbody.xml (for pedestrian detection from streaming
video). Haar Cascade frontal face classifier will be used in this project which
detects only the front face of the user and eliminates all background details.

Deep Neural Networks are becoming deeper and more complex. On adding
more layers to a Neural Network can make it more robust for image-related
tasks but can also cause them to lose accuracy. Therefore, to improve the
accuracy of our model, we will use Residual networks in place of deep neural
networks for age and gender estimation.

1.4 Objective of the study

To develop a algorithm which can predict Gender and Age of a user using
webcam.
CHAPTER 2: TECHNOLOGY USED

Python :- We have used python latest version “ 3.8.5” in the project.

OpenCV :- OpenCV (OPEN SOUCE COMPUTER VISION) is an open-source


BSD-licensed library that includes several hundreds of computer vision
algorithms. We will use many methods of opencv in this project.

Anaconda :- Anaconda Enterprise is an enterprise-ready, secure, and


scalable data science platform that empowers teams to govern data science
assets, collaborate, and deploy data science projects.
CHAPTER 3: IMPLEMENTATION

3.1 Methodology

Figure 3.1- the implementation contains 4 main steps:

1. Receive input frame from the webcam

2. Identify faces in the webcam and prepare these images for the deep

learning models, i.e. age, gender models.

3. Send processed faces to the models and receive prediction outcomes.

4. Render prediction outcomes with bounding boxes to screen.

Face detection algorithm: Haar Cascade

Stages in Haar Cascade Algorithm:


1. Haar Feature Selection- Features of the face like eyes, nose etc. Are
selected and their values are computed. There are two parts in each of these
features, white and black part. The white part represents the brighter part of
face and the black part depicts the darker part of our face. Sum of pixels of
white areas are subtracted from the sum of the black ones and their
difference is provided to the next stage.
2. Creating Integral images- Integral images are created by cumulative
addition of pixel values in both horizontal and vertical direction of a matrix.
These are created so as to make the computation of haar like features faster
and to reduce the number of operations.
3. Adaboost Training- The correctly classified part (denoted by +) of the
image is separated from the wrongly classified part (denoted by -). More
weightage is given to wrongly classified part as compared to correctly
classified one, iterations are done and we get a final classifier as result.
4. Cascading Classifier-All the three stages are combined together and a
properly trained classifier is ready.

Residual Networks

Deep Neural Networks have the problem of Vanishing gradient which is


overcome by Res Net. Whenever we use backpropagation and chain rule
of calculus, we face the problem of vanishing gradient. The problem of
vanishing gradient states that if we start moving in backward direction
that is from the last layers of the neural network to the earlier
layers(backpropagation), if we go on finding the derivative of each layer’s
weights and then multiply the derivative of each layer weights with the
previous layers, then we get a very less value of weight at the earlier
layers (this is the problem of vanishing gradient).
Res Net overcomes this problem by using a concept called Skip
connection in which the original input is added to the output of
convolutional block. By doing so, we skip some of the layers, so that the
value at the earlier layers do not become very less.

Figure 3.2 Residual block and concept of skip connections is shown.

This diagram explains the concept of Skip connections.


Y= F(X) + X
The main idea of Res Net is to make output equal to input. For that make
F(X)=0 so that Y=X. As Input= Output, so accuracy is maximum.

BLOCKS USED IN RESNET AND RESNET ARCHITECTURE


We have two types of blocks in Res Net- Identity and Convolution Block.
Identity block is used when input size is equal to output size whereas
Convolution Block is used whenever input size and output size is not equal.
Identity block is the same as a simple Res Net block using skip connections. In a
convolution block, we add an extra convolution layer from input to output.

Figure 3.3

This diagram shows the architecture of Res Net 50.


The first layer has a filter size of 7*7, with stride 2 and we have 64 such filters.
After the first layer, we have a 3*3 max pool with stride 2.
Pooling is done to reduce the size of the image and the number of parameters.
The most common types of pooling used are Average and Max pool. Here we
are using Max pool of 3*3 which means we divide the image into 3*3 blocks and
from each 3*3 block, we take only the maximum values.
The next layer consists of 1*1 filter size with 64 filters and we have 3 such
layers. Similarly, we have 3 layers with 3*3 filter size with 64 such filters and 3
layers with 1*1 filter size with 256 filters. The next layer is of filter size 1*1 with
128 such filters and stride of 2. The image size is changed on using stride of 2.
So, here we use a convolution block (as input size is not equal to output size).
Then we have 3 layers of 1*1 filter size and 128 filters. We have 4 layers each
of 3*3 filter size with 128 filters and 1*1 filter size with 512 such filters. Next,
we have a layer of 1*1 filter size with 256 filters and stride 2, so here also we
need a convolution block, followed by 5 more similar layers, 6 layers of each
3*3 filter size with 256 filters and 1*1 filter size with 1024 filters. Similarly, we
have one more convolution block for 1*1 filter size and 512 filters with stride 2
and 2 more similar layers. Then there are 3 layers each for 3*3 with 512 filters
and 1*1 size with 2048 filters.
At last, we have a layer for average pooling where only the average value of
each block/grid is considered followed by a fully connected layer with 1000
neurons.
So, in total we have 50 layers.

WORKFLOW OF MODULE 1 (Residual Networks)

Convolution layers include applying convolution operation on the input image


with a filter which helps in extracting important features in an image.
Batch normalization is done by taking a semi batch of values , taking the mean
and variance of all the values and then normalize each data value in terms of
mean.

WORKFLOW OF MODULE 2 (Real time demo)


Prerequisites:
Keras should be installed on the system. Keras is easy-to-use open-source
Python library for developing and evaluating deep learning models.
Open CV is used for Computer vision and image capturing.
Weights hdf5 file should be downloaded. Keras stores its model and
model weights separately. Model weights are all the parameters of the
model used in the layers of model. All the model weights are stored in
this weights hdf5 file.
Haar Cascade Frontal face classifier is used for face detection.

3.3 SOFTWARE USED

Python :- We have used python latest version “ 3.8.5” in the project.

OpenCV :- OpenCV (OPEN SOURCE COMPUTER VISION) is an open-source BSD-


licensed library that includes several hundreds of computer vision algorithms.
Anaconda :- Anaconda Enterprise is an enterprise-ready, secure, and scalable
data science platform that empowers teams to govern data science assets,
collaborate, and deploy data science projects.

3.3 HARDWARE USED


A windows system with webcam in it.
CHAPTER 4: EXPERIMENTAL RESULTS

4.1 Result and output

As we can see from the figure, the person shown in the image is a Male and his
actual age is between 20 to 25 years, the model correctly classifies the person
as male and also shows a correct estimation of his age.

There are many papers published on Face Recognition with various


technologies in it having various accuracies associated with it. By using our
methodology, we are able to get a better accuracy than other models

Figure 4.1 This figure shows the gender and age prediction of the given picture.

3.1 Merits
The biggest of this project that we can use this security mechanism in
websites, Apps and any other specific platform applications. As mobile phones
or website’s security is always a major issue, to ensure the security and
privacy, this project will play an important role in the same field.
It will capture the data in real time which hardly takes 4-5 minutes. The
training duration is also very short which completes in about few minutes.
This project is portable as well and can be used on any OS which has python
installed in it.

3.2 Demerits
It requires proper lightning while capturing images.
CHAPTER 5: CONCLUSIONS AND FUTURE SCOPE

5.1 Conclusions

Gender classifier and age estimator was built using Residual networks and
Keras. This part had two modules, one for Res Net and the other for real time
testing of the model. Similar to the first section, this section also used Haar
Cascade Classifier for face detection. A weights hdf5 file was used to store
Keras weights. A function is called which would pick up/load the Haar cascade
classifier and weights file and then all the weights were loaded into the Res Net
module. After which the webcam was initialised and OpenCV was used for
capturing images. If the image was classified according to the Haar Cascade
classifier, pre-processing was done on the image such as cropping of the face
etc. At last, we got a model that is able to work both as a Face Lock as well as a
Gender classifier and age estimator.

Figure 5.1 This figure shows the gender and age prediction of the given picture.

The has been matched successfully with 92% accuracy.

5.2 Future Scope

This project provides the vast opportunities of changes it. We can implement
this security mechanism in website and apps.

Despite these, this project may further be extended for numerous other
applications such as in forensics for preventing frauds, reporting duplicate
voters, document verification, attendance tracking, mood detection using facial
expressions , disease prediction by age estimation and facial expressions, etc.
References
https://docs.opencv.org/master/d6/d00/tutorial_py_root.html
https://docs.opencv.org/3.4/javadoc/org/opencv/face/LBPHFaceRecognizer.
html
D. B. Desai and S. N. Kavitha, "Face Anti-spoofing Technique Using CNN and
SVM," 2019 International Conference on Intelligent Computing and Control
Systems (ICCS), Madurai, India, 2019, pp. 37-41, doi:
10.1109/ICCS45141.2019.9065873.

Jenkins R, McLachlan JL, Renaud K. 2014. Facelock: familiarity-


based graphical authentication. PeerJ 2:e444
https://doi.org/10.7717/peerj.444
Authentication Lock for Application Integration Face Recognition Security Muhammad Aliff Romi Bin
Sharipudin, Firoz bin Yusuf Patel Dawoodi

A short review paper on Face detection using Machine learning Farhad


Navabifar(1), Mehran Emadi (2)Rubiyah Yusof(3) ,Marzuki Khalid(4)

S. Keller, M. Horstmann, N. Kashaev, and B. Klusemann, “Crack closure


mechanisms in residual stress fields generated by laser shock peening:
A combined experimental-numerical approach,” Eng. Fract. Mech., vol.
221, no. March, p. 106630, 2019, doi:
10.1016/j.engfracmech.2019.106630.
M. A. Abuzneid and A. Mahmood, “Enhanced human face recognition using
LBPH descriptor, multi-KNN, and back-propagation neural network,”
IEEE Access, vol. 6, no. c, pp. 20641–20651, 2018, doi:
10.1109/ACCESS.2018.2825310.
K. Kadir, M. K. Kamaruddin, H. Nasir, S. I. Safie, and Z. A. K. Bakti, “A
comparative study between LBP and Haar-like features for Face
Detection using OpenCV,” 2014 4th Int. Conf. Eng. Technol.
Technopreneuship, ICE2T 2014, vol. 2014-Augus, pp. 335–339, 2015,
doi: 10.1109/ICE2T.2014.7006273.

You might also like