0% found this document useful (0 votes)
8 views

Final Review Gender Classification

Uploaded by

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

Final Review Gender Classification

Uploaded by

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

Click to edit Master title style

GENDER
CLASSIFICATION OF
IMAGES identifying faces…

1
Click to edit Master title style

-> Saransh Goyal (19BAI10140)


-> Sandal Agrawal (19BAI10193)
-> Kratika Nandwana (19BAI10155)
-> Aishwarya Mudaliar (19BAI10182)

Group members

Guide

Dr Durga prasad
2 2
Click to edit Master title style
INDEX
. Introduction . Literature review

. Existing work . Module description


. Limitations . Wo r k f l o w e x p l a n a t i o n
. Proposed work and methodology . Implementation
. novelty of the project . Code snaps
. real time usage . testing and result
. hardware requirements . Summary
. software requirements

3 3
GENDER
Click to editCLASSIFICATION
Master title style
The aim of gender classification is to recognize the gender of a person
based on the characteristics that differentiate between masculinity
and femininity.

• In the area of artificial intelligence, gender classification is considered


to be one of the most important applications of pattern recognition
method.

• The progress of gender classification research has driven many


potential applications. For instance, a computer system with gender
recognition functions has a wide range of applications in fundamental
and applied research areas including: human-computer interaction
(HCI) , the security and surveillance industry, demographic research
and mobile application and video games.

4
EXISTING WORK
Click to edit Master title style

To understand the current research challenges, progress, and


opportunities of gender classification, we draw a comprehensive
overview by systematically summarizing and comparing the existing
gender classification methods which are based on the characteristics of
appearance, behavior, biometrics, bio-signals, and social network based
information. These characteristics or features are highlighted in several
aspects, including universality, distinctiveness, permanence, and
collectability to perform gender classification. 5 5
Click to edit Master title style
In particular, these four requirements for the qualified features are
listed
1. Universality: The features should be universal among each individual
which can be used for distinguishing gender. If the feature is unable to
be extracted from each individual, it is not appropriate for gender
classification.

2. Distinctiveness: The features should be sufficiently discriminative


between male and female, e.g., features such as appearance,
biometrics, bio-signal, and social network based information.

3. Permanence: The features should be stable and not change over a


long period of time, e.g., regardless of age and environment.

4. Collectability: The features should be measured quantitatively, which


has a great effect on the applications. The approach based on features
with high collectability such as a vision-based application is suitable for
real-time or on-line applications. In contrast, the approach based on
features with lower collectability can only be utilized in complicated or
off-line applications. 6
PROPOSED WORK
Click to edit Master AND
title style
METHODOLOGY
• About the dataset: The dataset from kaggle.com contains face
cleaned and cropped images of male and females faces. It is split into
training and validation and test set . Training set contains 23,000 images of
each male and female class and validation set contains 5,500 images of
each male and female.

DATA AUGMENTATION: We will use


data augmentation to create new training
data from the existing data simply making
slight changes so that our model sees
different images everytime and learns
patterns. 7 7
Click NORMALIZATION
DATA to edit Master title: style
It is achieved By subtracting the mean and dividing it by the
standard deviation.

The main aim of data normalization is to prevent partiality while


training the data caused by any input

GPU:
As our input data increases computation of the calculations
become complex, so we’ll be using GPU for parallel
computation which results in less processing time.

GPUs contain hundreds of cores optimized for performing


expensive matrix operations on floating-point numbers quickly,
making them ideal for training deep neural networks.

8 8
Click to edit Master title style
Convolutional neural
network : ConvNet/ cnn is a Deep Learning algorithm which can
take in an input image, assign learnable weights and
biases to various aspects/objects in the image and be able
to differentiate one from the other nn—Sequential.

to chain the layers and activation functions into a single


network architecture.

It adds the original input back to the output feature map


obtained by passing the input through one or more
convolutional layers.
Resnets: This small step drastically improves the performance of
the model 9
9
Click to edit Master
NOVELTY OF THEtitle style
PROJECT

Our model will be able to classify images on the basis of the gender.
Whether the given image is of a male or female with the use of lconvolutional
neural networks. In other words We will be collecting data and will associate
a gender (male or female) with it , according to the result of our analysis.
1010
Click to edit Master title style
Real time usage
The development and progress in gender recognition technology has lead
to many potential uses in a large application scope, because the gender
classification techniques can significantly improve the computer’s
perceptional and interactional capabilities.

For example, gender classification is able to improve the intelligence of a


surveillance system, analyze the customers’ demands for store
management, and allow the robots to perceive gender, etc.

To be concrete, applications of automatic gender classification can be


categorized in the following fields :

1111
Click to edit Master title style
1.Human-Computer Interaction
In the field of HCI , Robots or computers need to
identify and verify human gender to improve the
system performance based on personalized information.

2. surveillance systems
classifying gender in surveillance systems for public places
(e.g., bank, school) can assist intelligent security and
surveillance systems to track moving objects, detect abnormal
behaviors, and facilitate the security investigation off criminals
who intentionally try to hide their identity information.

1212
Click to edit
3.Commercial Master title style
Development
Gender classification is useful for guiding effective
marketing and establishing smart shopping environment, in
which production can be directed to specific users through
websites, electronic marketing, and advertising, etc.

4. Demographic Research
The application of a gender classification system helps
demographic research in efficiently collecting demographic
information.

Automatic identification of human gender enhances demographic


statistics. The ability to automatically detect gender information
acts as a supplementary method to demographic research.

1313
Click to edit Master title style
5. Mobile Application and Video Games
Gender classification can provide supportive information to improve the
user experience in mobile applications (apps) and video games. In mobile
apps, some researchers use this method to facilitate the use of the mobile
Internet by customizing apps according to gender.

In video games, male and female often have different preferences, which
would enable the use of gender information to provide their preferred
game characters or contents.

1414
Click to edit Master title style


HARDWARE
REQUIREMENTS
•Modern Operating System:

• Windows 7 or 10/Mac OS X 10.11 or higher, 64-


bit/Linux: RHEL 6/7, 64-bit (almost all libraries
also work in Ubuntu)
• GPU (graphical processing unit)

•x86 64-bit CPU (Intel / AMD architecture)


•4 GB RAM
•5 GB free disk space

15
Click to edit Master title style

“ SOFTWARE REQUIREMENTS
PYTHON WITH LIBRARIES :





Pytorch
Matplotlib
Numpy
Torchvision
• Resnets, Convolutional Neural network (cnn)

1616
System architecture
Click to edit Master title style

The system architecture used throughout our project is


based on convolutional neural network ( cnn ).

this network design is intended to be relatively shallow


so as to prevent over-fitting the data.

There are 8 convolution layers, and 2 residual layers in


our model

17
Click tostart
1. We editwith Master
the input pass title style
it through the first convolutional layer take its
output then pass it to batch normalization layer and relu actication function.

2. Then we take the output from the above layers and pass it through
convolutional layer batch normalization relu and max pooling then we pass
the output to our two of the residual layers which consist of convolutional
batch normalization and relu .

3. Now the output of this residual layer is added with the input which we passed
in those residual layers after max pooling.

4. Now we will repeat the whole procedure again this will be our residual layer
number two.

5 And the output which we will get from this second residual layer is sent to max
pooling then we flatten out the feature maps and pass them through linear layer
which will give us 2 outputs one for male and one for female .

1818
LITERATURE
Click to edit Master title style
REVIEW
A gender classification system uses face of a person from a given image to
tell the gender (male/female) of the given person. A successful
gender classification approach can boost the performance of many
applications including face recognition, smart human-computer
interface and computer-aided physiological or psychological analysis.
Usually facial images are used to extract features and then a
classifier is applied to the extracted features to learn a gender
recognizer. It contains a wide range of information regarding the
characteristics difference between male and female.

Recently, gender classification has been receiving more attention


since gender carries various distinguished information regarding
male and female in social activities . It is an active research topic in
Computer Vision and Biometrics fields.

19
Click to edit Master title style
The gender classification result is often a binary value, e.g., 1 or 0, representing either male or
female. The purpose of gender classification is to determine the gender of a person based on the
characteristics that appear in a person. The most commonly used methods for gender
classification are SVM(with RBF Kernel) and Adaboost combined with Linear SVM.In this project
we are using Convolutional Neural Network and ResNet to recognize the gender.

Convolutional neural network (CNN) is a class of artificial neural networks that has become
dominant in various computer applications. CNN is designed to automatically and adaptively learn
spatial hierarchies of features through back propagation by using multiple building blocks, such as
convolution layers, pooling layers, and fully connected layers. It is an active learning approach
which takes input as multimedia like images, videos or various 2D/3D data. It consists of
different weights for every hidden neuron expressed in mathematical expression of multi-
dimensional matrix. CNN frameworks are designed by a well-fixed combination of layers such as
narrow layers, sub sample layers, and full layers.

2020
Click to edit Master title style

ResNEt stands for Residual Networks. In this network we use a technique called skip connections .
The skip connection skips training from a few layers and connects directly to the output. The
advantage of adding this type of skip connection is because if any layer hurt the performance of
architecture then it will be skipped by regularization. So, this results in training very deep neural
network without the problems caused by vanishing/exploding gradient.

A significant advantage of the CNN over conventional approaches in pattern recognition is its ability to
simultaneously extract features, reduce data dimensionality, and classify in one network structure.
The CNN also has the ability to extract topological properties from a raw input image with no or
minimal preprocessing required. Our model consists of 8 convolutional layers and 2 residual layers in
cnn model.

2121
MODULE
Click to edit Master title style
DESCRIPTION
WE are making a gender classification
model with the help of cnn which
contains a corpus of 28k images.

Using this corpus we will train our


model bases on neural networks to get a
model which can classify images
(containing faces) as male and females
i m a g e s r e s p e c t i v e l y.

22
Click to edit Master title style
MODULE WORK FLOW
EXPLANATION
• downloading the dataset
We will start by downloading the dataset
in our jupyter notebook. Now this can be
easily done using “opendatasets” library
in python. We will import the library and
will use its “download” to download the
dataset by passing the link of the dataset
as a parameter in the download function

. Displaying the image


“Imshow” function from Matplotlib library
of python will be used to display images in
jpg or other image formats in our jupyter 2323
notebook
normalizing and augmenting
Click to edit Master title style
the data
This will be done using We will normalize the image
different functions from tensors by subtracting the
the torch-vision library mean and dividing by the
standard deviation across each
channel. As a result, the mean
of the data across each channel
is 0, and standard deviation is
1. Normalizing the data
prevents the values from any
one channel from
disproportionately affecting
the losses and gradients while
training, simply by having a
higher or wider range of values
than others.

24
WClick
e w i lto
l aedit
p p l y Master
r a n d o m ltitle
y chostyle
sen transformations while loading
images from the training dataset. Specifically, we will pad each
image by 4 pixels, and then take a random crop of size 32 x 32
pixels, and then flip the image horizontally with a 50%
probability. Since the transformation will be applied randomly
and dynamically each time a particular image is loaded, the
model sees slightly different images in each epoch of training,
which allows it generalize better.

2525
Setting up the
Click to edit gpu
Master title style
GPU, graphics processing unit is a
hardware.As the sizes of our models
and datasets increase, we need to use
GPUs to train our models within a
reasonable amount of time. GPUs
contain hundreds of cores optimized
for performing expensive matrix
operations on floating-point numbers
quickly, making them ideal for training
deep neural networks.

We are doing multiple large matrix


operations in our model, so to make
these operations faster we will set up
the GPU for training our model.
we will define a couple of helper
functions
(get_default_device & to_device) and a
helper class DeviceDataLoader to move
our model & data to the GPU as 2626
Click to edit Master title style
DEFINING THE MODEL
Now we will define the model by extending an ImageClassificationBase class which contains helper
methods for training & validation.

> The training_step function generates the predictions and calculates the loss using the cross
entropy function.

>the validation_step function generates the predictions calculates the loss using cross entropy
and calculates the accuracy using the acuuracy function which we defined using the torch.tensor
functions it calculates the accuracy of the model's prediction on an batch of inputs.

>validation_epoch_end function combines the accuracy and loss of all the batches by taking their
average and gives us an overall validation loss and accuracy

>epoch_end function prints all the results the training loss, validation loss and validation
accuracy .
2727
applying convolutional
Click to edit Master title style
neural networks and maxpool
We will use a convolutional neural network, using
the nn.Conv2d class from PyTorch.
The 2D convolution is a fairly simple operation we start with
a kernel, which is simply a small matrix of weights. This
kernel “slides” over the 2D input data, performing an
element wise multiplication with the part of the input it is
currently on, and then summing up the results into a single
output pixel

2828
There are certain advantages offered by
convolutional layers when working with image data:
Click to edit Master title style
>Fewer parameters: A small set of parameters (the kernel) is used to
calculate outputs of the entire image, so the model has much fewer parameters .
compared to a fully connected layer.
>Sparsity of connections: In each layer, each output element only depends on a
small number of input elements,
>Parameter sharing and spatial invariance: The features learned by a kernel in
one part of the image can be used to detect similar pattern in a different part of
another image.

We will also use a max-pooling layers to


progressively decrease the height & width of
the output tensors from each convolutional
layer.
Max-pool takes a block of 2x2 matrix and
takes out the maximum element from it .

29
Click to edit Master title style

The Conv2d layer transforms a 3-channel image to a 16-


channel feature map, and the MaxPool2d layer halves the
height and width. The feature map gets smaller as we add
more layers, until we are finally left with a small feature map,
which can be flattened into a vector. We can then add some
fully connected layers at the end to get vector of size 2 for
each image.
30
Click to
resnET
edit Master title style
We will now add residual blocks
to our convolutional neural
network.This residual block adds
the original input back to the
output feature map obtained by
passing the input through one or
more convolutional layers.
This seeming small change
produces a drastic improvement
in the performance of the model.
Also, after each convolutional
layer, we'll add a batch
normalization layer, which
normalizes the outputs of the
previous layer.

3131
Click to edit Master title style Adding some
improvements
Before we train the model, we're going to make a bunch of
small but important improvements to our fit function:

Learning rate scheduling: Instead of using a fixed learning


rate, we will use a learning rate scheduler, which will change
the learning rate after every batch of training. There are
many strategies for varying the learning rate during training,
and the one we'll use is called the "One Cycle Learning Rate
Policy", which involves starting with a low learning rate,
gradually increasing it batch-by-batch to a high learning rate
for about 30% of epochs, then gradually decreasing it to a
very low value for the remaining epochs

32
Click to edit Master title style

Weight decay: We also use weight decay,


which is yet another regularization
technique which prevents the weights
from becoming too large by adding an
additional term to the loss function.

Gradient clipping: Apart from the layer weights


and outputs, it also helpful to limit the values of
gradients to a small range to prevent undesirable
changes in parameters due to large gradient
values. This simple yet effective technique is
called gradient clipping.
3333
training the model
Click to edit Master title style
We are now ready to train our
model. We will do this by using the
evaluate function which we
created. And instead of SGD
(stochastic gradient descent),
we'll use the Adam optimizer
which uses techniques like
momentum and adaptive learning
rates for faster training.
After training our model reached
at maximum 98% percent of
accuracy.
Now we can test our model on
single images to see if it predicts
the correct gender or not. 3434
Click to edit Master title style

IMPLEMENTAT
ION
AND
CODE
SNAPS 35
Click to edit Master title style
Downloading the data set

3636
Click to edit Master
Importing title style
Libraries :

3737
Click to edit Master title style
Exploring the Data :

3838
Click to edit Master title style
Exploring the Data :

3939
Applying DataMaster
Click to edit Augmentation
title styleand
Normalization:

4040
Click to editBatches
Creating Master title
: style

4141
Click to editBatches
Creating Master title
: style

4242
Click to edit
Setting upMaster title style
the GPU :

4343
Click to edit Master title style
Setting up the GPU :

4444
Click to edit Master title style
Defining the Model :

4545
Click to editthe
Defining Master title style
Model :

4646
Applying Convolutional
Click to edit Neural
Master title style
Networks :

4747
Click to edit Master title style

4848
Click to edit
Adding theMaster title style
Improvements :

4949
Click to edit Master title style

5050
Click to editthe
Training Master title style
Model :

5151
Click to edit Master title style

5252
Click to edit Master title style

5353
Click to edit Master title style

5454
Click to edit Master title style

5555
Click to edit Master title style

5656
Testing
Click and
to edit result:-
Master title style
Image 1:

As we can see our label and predicted value is same i.e. female. Hence, our model works successfully. 5757
Testing
Click to editand result:-
Master title style
Image 2:-

As we can see our label and predicted value is same i.e. male. Hence, our model works successfully. 5858
Click to edit Master title style
Conclusion:-
•w e c a n s e e t h a t o u r m o d e l o f g e n d e r c l a s s i f i c a t i o n w o r k s
s u c c e s s f u l l y w i t h 9 8 % a c c u r a c y. W e b u i l d o u r m o d e l b y
going through various steps which involves : downloading
the required dataset, displaying the image, normalization
and augmentation of the data. Then we worked on setting
up the GPU. Thereafter we defined the model based on the
key points extracted by then. Then by applying
convolutional neural networks and maxpool, we further
directed our project. Residual blocks were added to
improve the performance of our model. Some additional
improvements were made to our fit function. Then we
finally trained our model and tested it. With all these key-
algorithms, we obtained a successful Gender 5959
Classification Model.
Click to edit Master title style

Thank You

60

You might also like