You are on page 1of 25

AGE AND GENDER

DETECTION
PROJECT REPORT

In the fulfillment for the award of

the degree Of

BACHELOR OF ENGINEERING
IN
COMPUTER SCIENCE AND ENGINEERING

Under the guidance of Submitted by


Mr. Jatinder Pal Singh Prince(1940020)
Assistant Professor
Computer Department

SANT LONGOWAL INSTITUTE OF ENGINEERING AND


TECHNOLOGY, LONGOWAL – 148106, DISTRICT- SANGRUR,
PUNJAB, INDIA
May, 2023

1
CERTIFICATE

This is to certify that this report entitled “AGE AND GENDER DETECTION”
comprises literature review carried out by “Prince(1940020)” under the guidance of
Mr. Jatinder Pal Singh (Assistant Professor, Deptt. Of C.S.E) during the period
between Jan, 2023 to May, 2023 for B.E. degree in Computer Science and
Engineering from Sant Longowal Institute of Engineering and Technology (SLIET).
The results presented to this have not been submitted previously to this or any other
University for B.E. and any other degree.

Prince
GCS/1940020

This is to certify that the above statement made by the candidates is correct to the
best of my knowledge.

Mr. Jatinder Pal Singh


Assistant Professor,
Deptt. of C.S.E. Sant
Longowal Institute of Engg. &
Tech.
Sangrur (Punjab)

2
Acknowledgement
We, students of degree final year, Computer Science and Engineering have
successfully completed the project on “AGE AND GENDER DETECTION” at our
Institute SANT LONGOWAL INSTITUTE OF ENGINEERING AND
TECHNOLOGY, Sangrur, Punjab. We would like to thank our project guide Mr.
Jatinder Pal Singh Sir and all our teachers at SLIET for making the learning of latest
technology like python and, deep learning during this project period in fun and easy
way.

We would also like to thank Dr. Gurjinder Kaur, Project Coordinator of 2019 batch
to provide us this opportunity which helped us to make ourselves technically sound
which will help us in our career upliftment. We would like to extend our thanks to
Department of Computer Science and Engineering for providing us this wonderful
opportunity. It was a great learning experience. Thank you to all who helped us to
complete this project well within time.

THANK YOU.

3
Abstract

Predicting the gender and age of people from their facial images is still on-going and
active research issue. Many methods have been proposed by researchers to solve this
problem but still there is a deficiency between the requirements and veritable
performances.

In this project "Age and Gender Detection" aims to develop a model that can accurately
detect the age and gender of an individual from an image or live video. The system will
utilize deep learning algorithms and computer vision techniques to extract facial features
and analyze them to predict the age and gender of the person. The project will involve
collecting and preprocessing a large dataset of images, training and testing various deep
learning models, and evaluating the performance of the system. The proposed system
will have potential applications in various domains such as security systems, marketing,
and healthcare. The success of the project will be measured by the accuracy of the
predictions and the efficiency of the system.

Nowadays research has explored to extracting auxiliary information from various


biometric techniques such as fingerprints, face, iris, palm, voice etc. This information
contains some features like gender, age, beard, moustache, scars, height, hair, skin color,
glasses, weight, facial marks, tattoos etc. All this information contributes more and more
during identification. The major changes that come across face recognition is to find age
& gender of the person. Age and gender, two of the key facial attributes, play a very
foundational role in social interactions, making age and gender estimation from a single
face image an important task in intelligent applications, such as access control, human-
computer interaction, law enforcement, marketing intelligence and visual surveillance.
This project is based upon computer vision the various terminologies used to process
image and detect age and gender of the person from the image.

4
List of Contents

Sr. No. Contents Page No.

1 Introduction 6

2 Problem Definition 7

3 Objectives 8

4 Methodology Used 12-27

4.1 Dataset Description 12-14

4.2 Workflow Diagram 15-16

4.3.1 First Stage: Data Preprocessing 17

4.3.2 Second Stage: Data Partitioning 17-18

4.3.3 Third Stage: Defining the Model 18-21

4.3.4 Fourth Stage: Training the Model 21-25

4.3.5 Fifth Stage: Creating the GUI 26-27

5 Result 28-29

6 Conclusion 30

7 Future Work 31

8 Reference 32

5
List of Figures

Sr. No. Figure Content Page No.

1 Dataset-1 12

2 Dataset-1 info() 12

3 Dataset-2 13

4 Dataset-2 info() 13

5 Workflow of Proposed Model 16

6 Hidden Layers 18

7 Defining the Model 19

8 Imported Libraries 21

9 Training the Model for Soil Analysis 23

10 Training the Model for Crop Prediction 25

11 GUI for Soil Analysis 26

12 GUI for Crop Prediction 27

13 Result of Soil Analysis 28

14 Table of Classes 28

15 Result of Crop Prediction 29

6
Introduction

Age and gender, two of the key facial attributes, play a very foundational role in social
interactions, making age and gender estimation from a single face image an important task in
intelligent applications, such as access control, human-computer interaction, law
enforcement, marketing intelligence and visual surveillance, etc. The enhancing of raw
images that are received from the camera sources, from satellites, aircrafts and the pictures
captured in day-to-day lives is called image processing. The images have been
processed through many different techniques and calculations have been made on the
basis and analysis of the studies. There is a need of analyzing and studying the digitally
formed images. There are two main and very common steps followed for image
processing. The improvement of an image such that the resulted image is of greater
quality and can be used by other programs, is called image enhancement. Other
technique is the most sought after technique used for extraction of information from an
image. There is a division of the image into certain number of parts or objects so that the
problem is solved. This process is called segmentation. A neural network consists of
many simple and similar compressing elements. It is a system with input st and outputs.
There are a number of internal parameters called weights. An artificial neural network is
made of set of processing elements which are also known as neurons or nodes. These
nodes are interconnected. Training in ANN is done through the track of the examples.

Keywords: Facial Images; Gender Prediction; Age Prediction; pretrained model, transfer
learning.

7
Problem Statement
"Age and gender detection is a common computer vision problem that involves
predicting the age and gender of a person from an image or video. This problem has a
wide range of applications in various fields such as marketing, security, and healthcare.
Age and gender detection can be used to analyze customer demographics, monitor
security in public places, and diagnose medical conditions that affect different age and
gender groups differently. However, accurate age and gender detection is a challenging
problem due to variations in lighting, pose, and facial expressions, as well as the large
variations in appearance among individuals of the same age and gender. Therefore, the
goal of this project is to develop a deep learning model that can accurately predict the
age and gender of a person from an image or video, using data augmentation techniques
to increase the size and diversity of the training data."

8
Objective
The objective of age and gender detection is to develop a machine learning model that can
accurately predict the age and gender of a person based on their image or video input. The
main goals of this objective include:

1. Increasing accuracy: The primary objective of age and gender detection is to develop a
model that can accurately predict the age and gender of a person. This involves training
the model on a diverse dataset and optimizing it using appropriate loss functions and
evaluation metrics.

2. Enhancing efficiency: Another objective of age and gender detection is to develop a


model that can make predictions quickly and efficiently. This involves optimizing the
model architecture, data preprocessing techniques, and hyperparameters to ensure that
the model can make predictions in real-time.

3. Improving generalization: Age and gender detection models should be able to


generalize well to unseen data. This requires careful selection of the training and testing
datasets, as well as the use of techniques such as data augmentation and regularization to
prevent overfitting.

4. Enabling real-world applications: The ultimate objective of age and gender detection
is to develop a model that can be used in real-world applications, such as security
systems, marketing research, and entertainment. This requires ensuring that the model is
scalable, robust, and capable of handling different types of input data and use cases.

9
Methodology Used

Dataset Description

The Adience dataset is a benchmark dataset used for age and gender classification in
machine learning. The dataset contains 26,580 images of faces of people with ages
ranging from 0 to 100 years old. The images were collected from the internet and cover a
wide range of ethnicities, genders, and lighting conditions.

The Adience dataset is divided into five subsets:


1. Training set: contains 16,399 images of faces for training the age and gender detection
models.
2. Validation set: contains 3,368 images of faces for validating the performance of the
age and gender detection models during training.
3. Testing set: contains 3,368 images of faces for evaluating the performance of the
trained age and gender detection models.
4. Benchmark subset: contains 1,000 images for benchmarking the performance of the
age and gender detection models across different datasets.
5. Second benchmark subset: contains 2,043 images for benchmarking the performance
of the age and gender detection models across different datasets.

The dataset provides annotations for each image, including the age range and gender of
the person in the image. The age ranges are categorized into eight age groups: 0-2, 4-6,
8-12, 15-20, 25-32, 38-43, 48-53, and 60+. The gender is categorized as either male or
female.

The Adience dataset contains approximately 26,000 images of faces, with roughly equal
numbers of male and female subjects. The images are taken in various lighting
conditions, with different facial expressions and poses, and they are labeled with the

10
subject's age and gender. The dataset is divided into five subsets: training set, validation
set, test set, fold 0, and fold 1. The training, validation, and test sets are used for training,
validation, and testing the models, while the fold subsets are used for cross-validation.
The Adience dataset has been widely used for benchmarking the performance of age and
gender detection models and for developing new techniques for face recognition and
analysis. It has been used in a variety of research applications, including computer
vision, machine learning, and social sciences. The Adience dataset is a commonly used
dataset for age and gender detection tasks. It is a large-scale dataset that contains images
of faces of various ages and genders. The dataset was created by a team of researchers
from the University of California, San Diego and the University of Toronto, and it was
designed to be used for training and evaluating age and gender classification models.
The Adience dataset is freely available for research purposes, and it has been used in
various research studies to evaluate the performance of different age and gender
classification models.

11
Workflow

The workflow of the “Age and Gender Detection machine learning project” that it
processes the data(images) and extract the features and detect the age and gender of the
person in image.
1. Data collection: Collect a large dataset of face images with corresponding age and
gender labels. The Adience dataset is a commonly used dataset for this task.

2. Data preprocessing: Preprocess the face images to ensure they are in a consistent
format and resolution. This can include steps such as cropping the face, resizing the
image, and normalizing the pixel values.

3. Data augmentation: Augment the dataset with additional images to increase the
diversity of the training data. Common augmentation techniques include random
cropping, flipping, rotation, and zooming.

4. Model selection: Choose a deep learning architecture such as Convolutional Neural


Networks (CNNs) or Residual Neural Networks (ResNets) that are commonly used for
image classification tasks.

5. Model training: Train the model on the augmented dataset using techniques such as
stochastic gradient descent (SGD) or Adam optimization. Monitor the training process to
ensure the model is not overfitting or underfitting the data.

6. Model evaluation: Evaluate the performance of the trained model on a separate


validation set or using cross-validation techniques. Use metrics such as accuracy,
precision, recall, and F1-score to assess the model's performance.

12
7. Hyperparameter tuning: Optimize the hyperparameters of the model such as learning
rate, batch size, and number of epochs, to improve the model's performance.

8. Model deployment: Deploy the trained model using OpenCV.


Overall, the workflow of an age and gender detection machine learning model involves
collecting and preprocessing the data, augmenting the dataset, selecting and training a
deep learning model, evaluating its performance, tuning the hyperparameters, and
deploying the model for real-time use.

Load Dataset

Preprocessing of images and data

Perform data augmentation

prepare a machine learning model

Training the model

Accuracy report

Deployment of model using OpenCV

Result

13
Fig-5. Workflow of Proposed
Model

First stage : Data extraction


 Identify the source of the data: The first step is to identify the source of the image
processing data for age and gender Detection. There are several sources for collecting
images, one is web scrapping, clicking your own images or get it from Kaggle
Dataset.
 Collect the data: Once the source of the data is identified, the next step is to collect the
data. This can be done by downloading the data from the source or by using an API to
collect the data.

Second Stage: Data Preprocessing


 Image and Data Preprocessing: Create appropriate dataset for images that specifies its
age and gender.

14
 Create a function to map the age groups to a single group.

15
 Encode the label

Third Stage: Data Augmentation


Albumentations: It is a computer vision tool that boosts the performance of deep
convolutional neural networks. The library is widely used in industry, deep learning
research, machine learning competitions, and open source projects.

16
Fourth Stage: Model:

We will use pretrained model to push our accuracy more then we got previously using our
own deep learning neural net.

Alexnet Architecture:

One thing to note here, since Alexnet is a deep architecture, the authors introduced padding to

prevent the size of the feature maps from reducing drastically. The input to this model is the

images of size 227X227X3.

To quickly summarize the architecture that we have seen in this article.

 It has 8 layers with learnable parameters.

 The input to the Model is RGB images.

 It has 5 convolution layers with a combination of max-pooling layers.

 Then it has 3 fully connected layers.

 The activation function used in all layers is Relu.

 It used two Dropout layers.

 The activation function used in the output layer is Softmax.

17
 The total number of parameters in this architecture is 62.3 million.

Fifth Stage: Train the model

Optimizer used: AdamW

Adam and AdamW are both optimization algorithms commonly used for training deep neural

networks. While Adam is a popular optimizer, AdamW is a modification of Adam that

addresses certain issues with Adam. Here are some key differences between the two

optimizers:

1. Weight decay: Adam and AdamW differ in their implementation of weight decay. Weight

decay is a regularization technique used to prevent overfitting in neural networks by adding a

penalty term to the loss function. In Adam, weight decay is implemented by adding a L2

regularization term to the gradient updates. In contrast, AdamW decouples weight decay from

the gradient updates, meaning that weight decay is applied directly to the weight parameters

instead of modifying the gradient updates. This can help prevent the optimization process

from being overly influenced by weight decay.

2. Bias correction: Adam and AdamW also differ in their bias correction strategy. Bias

correction is used to correct for the bias introduced in the first few iterations of the

optimization process. In Adam, bias correction is performed using the first and second

moment estimates, while in AdamW, it is performed only on the first moment estimates.

18
3. Convergence: Some research studies have shown that AdamW can lead to faster

convergence and better generalization performance compared to Adam, particularly in cases

where weight decay is important for regularization.

In summary, AdamW is a modification of Adam that addresses some issues related to weight

decay and bias correction. It is designed to improve the convergence and generalization

performance of deep neural networks. However, the effectiveness of each optimizer can

depend on the specific problem being solved and the architecture of the neural network.

Loss Function:

Cross entropy loss is a commonly used loss function in machine learning, particularly in

classification tasks. It is used to measure the difference between the predicted probability

distribution and the actual probability distribution of a categorical variable.

In classification tasks, the goal is to predict the probability distribution of the different classes

given an input. For example, in a binary classification problem, the goal is to predict the

probability of an input belonging to one of the two classes. The predicted probabilities can be

obtained by passing the input through a softmax activation function, which outputs a

probability distribution over the classes

The cross entropy loss is then calculated by comparing the predicted probability distribution

to the actual distribution of the classes. It measures the amount of information gained by the

model when the predicted probabilities are compared to the true probabilities. The cross

entropy loss is defined as:

L(y, y_hat) = - sum(y * log(y_hat))

19
where y is the actual probability distribution (represented as a one-hot encoded vector) and

y_hat is the predicted probability distribution. The loss is minimized when the predicted

probability distribution matches the actual distribution, i.e., when the model correctly predicts

the class of the input.

The cross entropy loss is widely used in machine learning because it provides a smooth and

continuous measure of the difference between the predicted and actual distributions. It is also

easy to compute and optimize using gradient-based optimization algorithms such as

stochastic gradient descent (SGD) and its variants.

FifthStage: Find the accuracy

Sixth Stage: Save the model and deploy using OpenCV


readNet` is a function provided by the OpenCV library for reading and loading pre-
trained deep learning models. It is a part of the `dnn` (deep neural network) module in
OpenCV.

The `readNet` function takes two arguments:


1. `model`: The path to the pre-trained model file on disk. This file should contain the
architecture and weights of the deep learning model. OpenCV supports different formats
for model files, including Caffe, TensorFlow, Torch, and Darknet.
2. `config`: The path to the configuration file for the model. This file specifies the
architecture of the model, including the layers and their parameters. The format of the

20
configuration file depends on the type of model being loaded.

We then read an input image and preprocess it using the `blobFromImage` function.
Finally, we pass the preprocessed image through the loaded model using the `setInput`
method and obtain the output predictions using the `forward` method.

Conclusion
In this work, it is concluded that age and gender research has been the focus of the last
few years. Despite the fact that many of the strategies of the past focused on issues of
age and sexuality, not so long ago, this work certainly focuses on the compelling
images taken in laboratory settings. Such settings do not adequately reflect the general
appearance types of current reality photos on social networking sites and online

21
archives. Web images, anytime, are not just about how complex they are: they are
equally saturated. Easy access to great collections of high qualities video readings of a
learning machine with ongoing preparation information. CNN can be used to provide
effects of age and age order, not by looking at the smallest size of the uneducated
image of age and sexuality, Finally, I hope that more training material will be found
with work age and gender cohesion that will allow effective techniques from other
forms of big data sets to be used this place. The subsequent framework was tried on the
Adience benchmark of unfiltered images and appeared to fundamentally beat late
cutting edge. Two critical conclusions can be produced using our experimental
outcomes. In the first place, CNN can be utilized to give enhanced age and gender
arrangement results, notwithstanding considering the much little size of contemporary
unconstrained image sets named for age and gender classification. Second, the straight
forwardness of our model suggests that more involved frameworks utilizing all the more
preparing information might well be able to do significantly enhancing results beyond
the one reported here.

Future Scope
The field of age and gender detection using machine learning has a wide range of
future possibilities and applications. Some potential future scopes of the age and
gender detection model include:

22
1. Personalized marketing: Age and gender detection models can be used for
personalized advertising, where ads can be targeted to specific age and gender groups.
Future research could focus on developing models that can detect other attributes, such
as facial expression, ethnicity, or emotional state to enable even more personalized
advertising.

2. Healthcare: Age and gender detection models could be used in healthcare to detect
age-related diseases, monitor patient recovery, and develop personalized treatments.
Future research could focus on developing models that can detect other health-related
attributes and biomarkers.

3. Security systems: Age and gender detection models can be used for identity
verification and access control in security systems. Future research could focus on
developing models that can detect other biometric attributes, such as facial recognition
or iris recognition.

4. Social sciences: Age and gender detection models can be used in social sciences to
study demographics and trends in population. Future research could focus on
developing models that can detect other social attributes, such as income, education, or
occupation.

5. Human-robot interaction: Age and gender detection models can be used for human-
robot interaction, where robots can adapt their behavior and communication style to
specific age and gender groups. Future research could focus on developing models that
can detect other human attributes, such as emotions and personality traits.

6. Education: Age and gender detection models can be used in educational settings to
provide personalized learning experiences based on the age and gender of the students.
Future research could focus on developing models that can detect other learning-related
attributes, such as learning styles or cognitive abilities.

Overall, the future scope of age and gender detection models is vast, and there are
many potential applications in various fields. Continued research and development in
this area could lead to exciting new possibilities and advancements.

23
References

1. A. Kumar and F. Shaik,” Importance of Image Processing”, 2016.

2. Hang Qi and Liqing Zhang,” Age Classification System with ICA Based Local

24
Facial Features”, 2009 Springer-Verlag Berlin Heidelberg.

3. Eran Eidinger, Roee Enbar, and Tal Hassner,” Age and Gender Estimation of
Unfiltered Faces”, 2014 IEEE.

4. Aditya K. Saxena, Shweta Sharma and Vijay K. Chaurasiya,” Neural Network


based Human Age-group Estimation in Curvelet Domain”, 2015 The Authors
Published by Elsevier.

5. J. Chen, S. Shan, C. He, G. Zhao, M. Pietikainen, X. Chen, and W. Gao. Wld: “A


robust local image descriptor”, Trans.Pattern Anal. Mach. Intell.,

6. T. F. Cootes, G. J. Edwards, and C. J. Taylor. “Active appearance models”, In


European Conf. Comput. Vision, pages 484–498. Springer, 1998.

7. C. Cortes and V. Vapnik. “Support-vector networks”, Machinelearning,


20(3):273–297, 1995.

8. E. Eidinger, R. Enbar, and T. Hassner. “Age and gender estimation of unfiltered


faces”, Trans. on Inform.Forensics andSecurity, 9(12), 2014.

9. Y. Fu, G. Guo, and T. S. Huang. “Age synthesis and estimation via faces: A
survey”, Trans. Pattern Anal. Mach. Intell., 32(11):1955–1976, 2010.

10. Y. Fu and T. S. Huang. “Human age estimation with regression on discriminative


aging manifold”, Int. Conf. Multimedia,10(4):578–584, 2008.

25

You might also like