Age and Gender Classiication Report

You might also like

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

ABSTRACT

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.
Automatic age and gender classification has become relevant to an
increasing amount of applications, particularly since the rise of social
platforms and social media. Nevertheless, performance of existing
methods on real-world images is still significantly lacking, especially
when compared to the tremendous leaps in performance recently
reported for the related task of face recognition. Age and Gender
Classification using Convolutional Neural Networks gives more
accuracy compared to the previous one.
CHAPTER 1

INTRODUCTION

Face detection is a method of recognizing if there is a face in an image

or not which is also called as object detection. OpenCV is widely used

for object detection. The goal of face emotion analysis is to detect and

identify the different types of emotions of a person such as happy, sad,

anger, confused, surprise, etc. A gender categorizing model uses face

from a given image to predict the gender (male or female) based on their

appearance like baldness, long hair, beard and mustache .In age

classification, we classify based on wrinkles, hair color and also size of

face etc. Deep learning which is a subset of machine learning that uses

several layers neural network to repeatedly gain higher level of features

from the given input images. The concept of deep learning was inspired

by how neurons function in our brain hence it’s also called deep neural

network. A neural network is a sequence of process that is capable to

identify hidden relationships in a set of data and the process is similar to

the operation of human brain. We use a deep learning model called


convolutional neural network which takes input images and allocate

importance (learnable weights and biases) to different aspects/objects in

an image and also capable of differentiating one from the other. When

compared to other classification algorithms, the pre-processing required

in a ConvNet is comparatively lesser.


CHAPTER 2

LITERATURE SURVEY

 Understanding and Comparing Deep Neural Networks for Age

and Gender Classification

Recently, deep neural networks have demonstrated excellent

performances in recognizing the age and gender on human face

images. However, these models were applied in a black-box

manner with no information provided about which facial features

are actually used for prediction and how these features depend on

image preprocessing, model initialization and architecture choice.

We present a study investigating these different effects. In detail,

our work compares four popular neural network architectures,

studies the effect of pretraining, evaluates the robustness of the

considered alignment preprocessings via cross-method test set

swapping and intuitively visualizes the model's prediction

strategies in given preprocessing conditions using the recent Layer-

wise Relevance Propagation (LRP) algorithm. Our evaluations on


the challenging Audience benchmark show that suitable parameter

initialization leads to a holistic perception of the input,

compensating artificial data representations. With a combination

of simple preprocessing steps, we reach state of the art

performance in gender recognition.

 A hybrid deep learning CNN–ELM for age and gender

classification

Automatic age and gender classification has been widely used in a

large amount of applications, particularly in human-computer

interaction, biometrics, visual surveillance, electronic customer,

and commercial applications. In this paper, we introduce a hybrid

structure which includes Convolutional Neural Network (CNN)

and Extreme Learning Machine (ELM), and integrates the synergy

of two classifiers to deal with age and gender classification.

The hybrid architecture makes the most of their advantages: CNN

is used to extract the features from the input images while ELM

classifies the intermediate results. We not only give the detailed

deployment of our structure including design of parameters and


layers, analysis of the hybrid architecture, and the derivation

of back-propagation in this system during the iterations, but also

adopt several measures to limit the risk of overfitting. After that,

two popular datasets, such as, MORPH-II and Adience

Benchmark, are used to verify our hybrid structure. Experimental

results show that our hybrid architecture outperforms other studies

on the same datasets by exhibiting significant performance

improvement in terms of accuracy and efficiency.

 Age and gender classification from speech and face images by

jointly fine-tuned deep neural networks

The classification of human's age and gender from speech and face

images is a challenging task that has important applications in real-

life and its applications are expected to grow more in the

future. Deep neural networks (DNNs) and Convolutional neural

networks (CNNs) are considered as one of the state-of-art systems

as feature extractors and classifiers and are proven to be very

efficient in analyzing problems with complex feature space. In this


work, we propose a new cost function for fine-tuning two DNNs

jointly. The proposed cost function is evaluated by using speech

utterances and unconstrained face images for age and

gender classification task. The proposed classifier design consists

of two DNNs trained on different feature sets, which are extracted

from the same input data. Mel-frequency cepstral

coefficients (MFCCs) and fundamental frequency (F0) and the

shifted delta cepstral coefficients (SDC) are extracted from speech

as the first and second feature sets, respectively. Facial

appearance and the depth information are extracted from face

images as the first and second feature sets, respectively. Jointly

training of two DNNs with the proposed cost function improved

the classification accuracies and minimized the over-fitting effect

for both speech-based and image-based systems. Extensive

experiments have been conducted to evaluate the performance and

the accuracy of the proposed work. Two publicly available

databases, the Age-Annotated Database of the German Telephone

Speech database (aGender) and the Adience database, are used to


evaluate the proposed system. The overall accuracy of the

proposed system is calculated as 56.06% for seven speaker classes

and overall exact accuracy is calculated as 63.78% for Adience

database.

 Local Deep Neural Networks for Age and Gender

Classification

Local deep neural networks have been recently introduced for

gender recognition. Although, they achieve very good performance

they are very computationally expensive to train. In this work, we

introduce a simplified version of local deep neural networks which

significantly reduces the training time. Instead of using hundreds

of patches per image, as suggested by the original method, we

propose to use 9 overlapping patches per image which cover the

entire face region. This results in a much reduced training time,

since just 9 patches are extracted per image instead of hundreds, at

the expense of a slightly reduced performance. We tested the

proposed modified local deep neural networks approach on the


LFW and Adience databases for the task of gender and age

classification. For both tasks and both databases the performance is

up to 1% lower compared to the original version of the algorithm.

We have also investigated which patches are more discriminative

for age and gender classification. It turns out that the mouth and

eyes regions are useful for age classification, whereas just the eye

region is useful for gender classification.

 Age and gender classification using brain–computer interface

With the development of Internet of things (IOT), it is now

possible to connect various heterogeneous devices together using

Internet. The devices are able to share their information for various

applications including health care, security and monitoring. IOT

facilitates patients to self-monitor their physiological states

invariably and doctors to monitor their patients remotely.

Electroencephalography (EEG) provides a monitoring method to

record such electrical activities of the brain using sensors. In this

paper, we present an automatic age and gender prediction


framework of users based on their neurosignals captured during

eyes closed resting state using EEG sensor. Using EEG sensor,

brain activities of 60 individuals with different age groups varying

between 6 and 55 years and gender (i.e., male and female) have

been recorded using a wireless EEG sensor. Discrete wavelet

transform frequency decomposition has been performed for feature

extraction. Next, random forest classifier has been applied for

modeling the brain signals. Lastly, the accuracies have been

compared with support vector machine and artificial neural

network classifiers. The performance of the system has been tested

using user-independent approach with an accuracy of 88.33 and

96.66% in age and gender prediction, respectively. It has been

analyzed that oscillations in beta and theta band waves show

maximum age prediction, whereas delta rhythm leads to highest

gender classification rates. The proposed method can be extended

to different IOT applications in healthcare sector where age and

gender information can be automatically transmitted to hospitals

and clinics through Internet.


 Age and gender recognition in the wild with deep attention

Face analysis in images in the wild still pose a challenge for

automatic age and gender recognition tasks, mainly due to their

high variability in resolution, deformation, and occlusion.

Although the performance has highly increased thanks to

Convolutional Neural Networks (CNNs), it is still far from optimal

when compared to other image recognition tasks, mainly because

of the high sensitiveness of CNNs to facial variations. In this

paper, inspired by biology and the recent success of attention

mechanisms on visual question answering and fine-grained

recognition, we propose a novel feedforward attention mechanism

that is able to discover the most informative and reliable parts of a

given face for improving age and gender classification. In

particular, given a downsampled facial image, the proposed model

is trained based on a novel end-to-end learning framework to

extract the most discriminative patches from the original high-

resolution image. Experimental validation on the standard Adience,


Images of Groups, and MORPH II benchmarks show that

including attention mechanisms enhances the performance of

CNNs in terms of robustness and accuracy.


CHAPTER 3

SYSTEM ANALYSIS

3.1 EXISITING SYSTEM

The face of human holds significant amount of qualities and data about

the human identification, for example, appearance, race, gender

classification, and age. Humans can identify and examine these data

effectively, for example, most of human can perceive human attributes

like gender classification. The most of existing systems use only opencv

for age and gender classification. The Existing system not suitable for

large enterprises.

3.1.1 DRAWBACK

 Low accuracy.

 Less number of datasets trained .

 Not suitable for large enterprises.

 Age and gender classification is time

 consuming process
3.2 PROPOSAL SYSTEM

The dataset shows different levels of heart disease presence from 1 to 4

and 0 for the absence of the disease. We have 303 rows of people data

with 13 continuous observations of different symptoms. The input

parameters are age,sex,chest pain,resting blood

pressure,cholesterol,blood sugar,electrocardiographic,heart rate and

many other risk factors based on this features our project will predict the

heart stroke. The dataset shows different levels of heart stroke disease

presence from 1 to 4 and 0 for the absence of disease. Supervised

machine learning algorithm are used to predict the heart stroke.

3.2.1 ADVANTAGE

 High performance and accuracy rate.

 Low complexity.

 More number of datasets.

3.3 FEASIBILITY STUDY


A feasibility study is carried out to select the best system that

meets performance requirements. The main aim of the feasibility study

activity is to determine that it would be financially and technically

feasible to develop the product.

3.3.1 TECHNICAL FEASIBILITY

This is concerned with specifying the software will successfully

satisfy the user requirement. Open source and business-friendly and it is

truly cross platform, easily deployed and highly extensible.

3.3.2 ECONOMIC FEASIBILITY

Economic analysis is the most frequently used technique for

evaluating the effectiveness of a proposed system. The enhancement of

the existing system doesn’t incur any kind of drastic increase in the

expenses. Python is open source and ready available for all users. Since

the project is runned in python and juypter notebook hence is cost

efficient.
CHAPTER 4

HARDWARE AND SOTWARE REQUIREMENT

4.1 Hardware System Configuration

 Processor - Intel Core i7

 RAM - 4 GB

 Hard Disk - 500 GB

4.2 Software System Configuration

 Programming Language : Python 3.8

4.3 SOFTWARE SPECIFICATION

4.3.1 MACHINE LEARNING

Machine learning is a subfield of artificial intelligence (AI). The

goal of machine learning generally is to understand the structure of data

and fit that data into models that can be understood and utilized by

people. Although machine learning is a field within computer science, it

differs from traditional computational approaches. In traditional


computing, algorithms are sets of explicitly programmed instructions

used by computers to calculate or problem solve. Machine learning

algorithms instead allow for computers to train on data inputs and use

statistical analysis in order to output values that fall within a specific

range. Because of this, machine learning facilitates computers in

building models from sample data in order to automate decision-making

processes based on data inputs.

Any technology user today has benefitted from machine learning. Facial

recognition technology allows social media platforms to help users tag

and share photos of friends. Optical character recognition (OCR)

technology converts images of text into movable type. Recommendation

engines, powered by machine learning, suggest what movies or

television shows to watch next based on user preferences. Self-driving

cars that rely on machine learning to navigate may soon be available to

consumers. Machine learning is a continuously developing field.

Because of this, there are some considerations to keep in mind as you


work with machine learning methodologies, or analyze the impact of

machine learning processes.

Here in this thesis, we are providing basic info of the common machine

learning methods of supervised and unsupervised learning, and common

algorithmic approaches in machine learning, including the k-nearest

neighbour algorithm, decision tree learning, and deep learning.

4.3.2 SUPERVISED LEARNING

In machine learning, tasks are generally classified into broad categories.

These categories are based on how learning is received or how feedback

on the learning is given to the system developed. Two of the most

widely adopted machine learning methods are supervised learning which

trains algorithms based on example input and output data that is labeled

by humans, and unsupervised learning which provides the algorithm

with no labeled data in order to allow it to find structure within its input

data.Let’s explore these methods in more detail.

The majority of practical machine learning uses supervised learning.

Supervised learning is where you have input variables (x) and an output
variable (Y) and you use an algorithm to learn the mapping function

from the input to the output Y = f(X) . The goal is to approximate the

mapping function so well that when you have new input data .(x) that

you can predict the output variables (Y) for that data. Techniques of

Supervised Machine Learning algorithms include linear and logistic

regression, multi-class classification, Decision Trees and support vector

machines. Supervised learning requires that the data used to train the

algorithm is already labeled with correct answers. For example, a

classification algorithm will learn to identify animals after being trained

on a dataset of images that are properly labeled with the species of the

animal and some identifying characteristics. Supervised learning

problems can be further grouped into Regression and Classification

problems. Both problems have as goal the construction of a succinct

model that can predict the value of the dependent attribute from the

attribute variables. The difference between the two tasks is the fact that

the dependent attribute is numerical for regression and categorical for

classification.
4.3.3 CLASSIFICATION

As the name suggests, Classification is the task of “classifying things”

into sub- categories. But, by a machine. If that doesn’t sound like much,

imagine your computer being able to differentiate between you and a

stranger. Between a potato and a tomato. Between an A grade and a F. In

Machine Learning and Statistics, Classification is the problem of

identifying to which of a set of categories (sub populations), a new

observation belongs to, on the basis of a training set of data containing

observations and whose categories membership is known.

TYPES OF CLASSIFICATION

Classification is of two types:

• Binary Classification: When we have to categorize given data

into 2 distinct classes. Example – On the basis of given health conditions

of a person, we have to determine whether the person has a certain

disease or not.
• Multiclass Classification : The number of classes is more than 2.

For Example

– On the basis of data about different species of flowers, we have to

determine which specie does our observation belong to

Fig 2 : Binary and Multiclass Classification. Here x1 and x2 are our

variables upon which the class is predicted. Suppose we have to predict

whether a given patient has a certain disease or not, on the basis of 3

variables, called features. Which means there are two possible outcomes:

1. The patient has the said disease. Basically a result labeled “Yes” or

“True”.

2. The patient is disease free. A result labeled “No” or “False”.

This is a binary classification problem. We have a set of observations

called training data set, which comprises of sample data with actual

classification results. We train a model, called Classifier on this data set,

and use that model to predict whether a certain patient will have the
Fig : Generalized Classification Block Diagram.

1. X : pre-classified data, in the form of a N*M matrix. N is the no. of

observations and M is the number of features

2. y : An N-d vector corresponding to predicted classes for each of the N

observations.

3. Feature Extraction : Extracting valuable information from input X

using a series of transforms.

4. ML Model : The “Classifier” we’ll train.

5. y’ : Labels predicted by the Classifier.

6. Quality Metric: Metric used for measuring the performance of the

model.
7. ML Algorithm: The algorithm that is used to update weights w’,

which update the model and “learns” iteratively.

Types of Classifiers (Algorithms)

There are various types of classifiers. Some of them are :

• Linear Classifiers: Logistic Regression

• Tree Based Classifiers: Decision Tree Classifier

• Support Vector Machines

• Artificial Neural Networks

• Bayesian Regression

• Gaussian Naive Bayes Classifiers

• Stochastic Gradient Descent (SGD) Classifier

• Ensemble Methods: Random Forests, AdaBoost, Bagging

Classifier, Voting Classifier, Extra Trees Classifier

Practical Applications of Classification


• Google’s self driving car uses deep learning enabled classification

techniques which enables it to detect and classify obstacles.

• Spam E-mail filtering is one of the most widespread and well

recognized uses of Classification techniques.

• Detecting Health Problems, Facial Recognition, Speech

Recognition, Object Detection, Sentiment Analysis all use Classification

at their core.

4.3.4 REGRESSION

A regression problem is when the output variable is a real or continuous

value, such as “salary” or “weight”. Many different models can be used,

the simplest is the linear regression. It tries to fit data with the best

hyper-plane which goes through the points.


FIG : LINEAR REGRESSION MODEL

FIG: TYPES OF REGRESSION MODELS

4.3.5 UNSUPERVISED LEARNING

Unsupervised learning is where we only have input data (X) and no

corresponding output variables. The goal for unsupervised learning is to

model the underlying structure or distribution in the data in order to

learn more about the data. These are called unsupervised learning

because unlike supervised learning above there is no correct answers and


there is no teacher. Algorithms are left to their own devises to discover

and present the interesting structure in the data. Unsupervised learning

problems can be further grouped into clustering and association

problems.

4.3.5.1 CLUSTERING

It is basically a type of unsupervised learning method. An unsupervised

learning method is a method in which we draw references from datasets

consisting of input data without labeled responses. Generally, it is used

as a process to find meaningful structure, explanatory underlying

processes, generative features, and groupings inherent in a set of

examples. Clustering is the task of dividing the population or data points

into a number of groups such that data points in the same groups are

more similar to other data points in the same group and dissimilar to the

data points in other groups. It is basically a collection of objects on the

basis of similarity and dissimilarity between them.For example, the data

points in the graph below clustered together can be classified into one
single group. We can distinguish the clusters, and we can identify that

there are 3 clusters in the below picture.

Fig : Clustering Example

These data points are clustered by using the basic concept that the data

point lies within the given constraint from the cluster center. Various

distance methods and techniques are used for calculation of the outliers.

Clustering is very much important as it determines the intrinsic grouping

among the unlabeled data present. There are no criteria for a good

clustering. It depends on the user, what is the criteria they may use

which satisfy their need. For instance, we could be interested in finding


representatives for homogeneous groups (data reduction), in finding

“natural clusters” and describe their unknown properties (“natural” data

types), in finding useful and suitable groupings (“useful” data classes) or

in finding unusual data objects (outlier detection). This algorithm must

make some assumptions which constitute the similarity of points and

each assumption make different and equally valid clusters.

4.3.5.1.1 Clustering Methods:

1. Density-Based Methods: These methods consider the clusters as

the dense region having some similarity and different from the lower

dense region of the space. These methods have good accuracy and

ability to merge two clusters. Example DBSCAN

(Density-Based Spatial Clustering of Applications with Noise) , OPTICS

(Ordering Points to Identify Clustering Structure) etc.

2. Hierarchical Based Methods: The clusters formed in this method

forms a tree type structure based on the hierarchy. New clusters are

formed using the previously formed one. It is divided into two categories
• Agglomerative (bottom up approach)

• Divisive (top down approach) .

3. Partitioning Methods: These methods partition the objects into k

clusters and each partition forms one cluster. This method is used to

optimize an objective criterion similarity function such as when the

distance is a major parameter example K-means, CLARANS (Clustering

Large Applications based upon randomized Search) etc.

4. Grid-based Methods: In this method the data space are

formulated into a finite number of cells that form a grid-like structure.

All the clustering operation done on these grids are fast and independent

of the number of data objects example STING (Statistical Information

Grid), wave cluster, CLIQUE (Clustering In Quest) etc.

Clustering Algorithms:

• K-Means Clustering.

• Mean-Shift Clustering for a single sliding window.

• The entire process of Mean-Shift Clustering.


• DBSCAN Smiley Face Clustering.

• EM Clustering using GMMs.

• Agglomerative Hierarchical Clustering.

4.4.1 PYTHON

Python is an interpreted, high-level and general-purpose programming

language. Created by Guido van Rossum and first released in 1991,

Python's design philosophy emphasizes code readability with its notable

use of significant whitespace. Its language constructs and object-


oriented approach aim to help programmers write clear, logical code for

small and large-scale projects.

Python is  dynamically typed and garbage- collected. It supports

multiple programming paradigms,

including structured (particularly, procedural), object-oriented,

and functional programming. Python is often described as a "batteries

included" language due to its comprehensive standard library.

Python was created in the late 1980s as a successor to the ABC

language. Python 2.0, released in 2000, introduced features like list

comprehensions and a garbage collection system with reference

counting.

Python 3.0, released in 2008, was a major revision of the language that

is not completely backward-compatible, and much Python 2 code does

not run unmodified on Python 3.

The Python 2 language was officially discontinued in 2020 (first planned

for 2015), and "Python 2.7.18 is the last Python 2.7 release and therefore
the last Python 2 release." No more security patches or other

improvements will be released for it. With Python 2's end-of-life, only

Python 3.5.x and later are supported.

Python interpreters are available for many operating systems. A global

community of programmers develops and maintains CPython, a free and

open-source reference implementation. A non-profit organization,

the Python Software Foundation, manages and directs resources for

Python and CPython development.

4.4.1.1 FEATURES

Python is a multi-paradigm programming language. Object-oriented

programming and structured programming are fully supported, and

many of its features support functional programming and aspect-oriented

programming (including by metaprogramming  and metaobjects (magic

methods)).  Many other paradigms are supported via extensions,

including design by contract  and logic programming.


Python uses dynamic typing and a combination of reference

counting and a cycle-detecting garbage collector for memory

management. It also features dynamic name resolution (late binding),

which binds method and variable names during program execution.

Python's design offers some support for functional programming in

the Lisp tradition. It has filter, map, and reduce functions; list

comprehensions, dictionaries, sets, and generator expressions.  The

standard library has two modules (itertools and functools) that

implement functional tools borrowed from Haskell and Standard ML.

The language's core philosophy is summarized in the document The Zen

of Python (PEP 20), which includes aphorisms such as:

 Beautiful is better than ugly.

 Explicit is better than implicit.

 Simple is better than complex.

 Complex is better than complicated.

 Readability counts.
Rather than having all of its functionality built into its core, Python was

designed to be highly extensible. This compact modularity has made it

particularly popular as a means of adding programmable interfaces to

existing applications. Van Rossum's vision of a small core language with

a large standard library and easily extensible interpreter stemmed from

his frustrations with ABC, which espoused the opposite approach.

Python strives for a simpler, less-cluttered syntax and grammar while

giving developers a choice in their coding methodology. In contrast

to Perl's "there is more than one way to do it" motto, Python embraces a

"there should be one—and preferably only one—obvious way to do it"

design philosophy.[57] Alex Martelli, a Fellow at the Python Software

Foundation and Python book author, writes that "To describe something

as 'clever' is not considered a compliment in the Python culture."

Python's developers strive to avoid premature optimization, and reject

patches to non-critical parts of the CPython reference implementation

that would offer marginal increases in speed at the cost of clarity.


[59]
 When speed is important, a Python programmer can move time-
critical functions to extension modules written in languages such as C,

or use PyPy, a just-in-time compiler. Cython is also available, which

translates a Python script into C and makes direct C-level API calls into

the Python interpreter.

An important goal of Python's developers is keeping it fun to use. This is

reflected in the language's name a tribute to the British comedy

group Monty Python and in occasionally playful approaches to tutorials

and reference materials, such as examples that refer to spam and eggs

(from a famous Monty Python sketch) instead of the standard foo and

bar.

A common neologism in the Python community is pythonic, which can

have a wide range of meanings related to program style. To say that

code is pythonic is to say that it uses Python idioms well, that it is

natural or shows fluency in the language, that it conforms with Python's

minimalist philosophy and emphasis on readability. In contrast, code

that is difficult to understand or reads like a rough transcription from

another programming language is called unpythonic.


Users and admirers of Python, especially those considered

knowledgeable or experienced, are often referred to as Pythonistas.


CHAPTER 5

ARCHITECTURE

5.1 SYSTEM ARCHITECTURE


CHAPTER 6

SYSTEM MODULES

6.1 MODULES

 Face detection with Haar cascades


 Gender Recognition with CNN
 Age Recognition with CNN

6.2 MODULES DESCRIPTION

 Face detection with Haar cascades


Open CV provide direct methods to import Haar-cascades and use
them to detect faces. To apply face detection, which detects the
presence and location of a face in an image, but does not identify
it. To extract the 128-d feature vectors (called “embeddings”) that
quantify each face in an image. Haar cascade XML file which is a
classifier used to identify a specific object from the webcam. The
aarcascasde_frontalface_default.xml provided by OpenCV used to
recognize frontal face. OpenCV connects to the webcam which
user can use to scan their faces for classification of age, gender and
emotion.
 Gender Recognition with CNN
In the dnn package, OpenCV has provided a class called Net which
can be used to populate a neural network. Furthermore, these
packages support importing neural network models from well
known deep learning frameworks like caffe, tensorflow and torch.
CNN models as caffe models. Therefore, we will be using the
CaffeImporter import that model into our application.
 Age Recognition with CNN

This is almost similar to the gender detection part except that the
corresponding prototxt file and the caffe model file are
deploy_agenet.prototxt” and “age_net.caffemodel”. Furthermore, the
CNN’s output layer (probability layer) in this CNN consists of 8
values for 8 age classes (“0–2”, “4–6”, “8–13”, “15–20”, “25–32”,
“38–43”, “48–53” and “60-”)

1 .prototxt — The definition of CNN goes in here. This file defines


the layers in the neural network, each layer’s inputs, outputs and
functionality.

2 .caffemodel — This contains the information of the trained neural


network (trained model).
CHAPTER 7

SAMPLE CODE

import cv2

import math

import argparse

def highlightFace(net, frame, conf_threshold=0.7):

frameOpencvDnn=frame.copy()

frameHeight=frameOpencvDnn.shape[0]

frameWidth=frameOpencvDnn.shape[1]

blob=cv2.dnn.blobFromImage(frameOpencvDnn, 1.0, (300, 300),


[104, 117, 123], True, False)

net.setInput(blob)

detections=net.forward()

faceBoxes=[]

for i in range(detections.shape[2]):
confidence=detections[0,0,i,2]

if confidence>conf_threshold:

x1=int(detections[0,0,i,3]*frameWidth)

y1=int(detections[0,0,i,4]*frameHeight)

x2=int(detections[0,0,i,5]*frameWidth)

y2=int(detections[0,0,i,6]*frameHeight)

faceBoxes.append([x1,y1,x2,y2])

cv2.rectangle(frameOpencvDnn, (x1,y1), (x2,y2), (0,255,0),


int(round(frameHeight/150)), 8)

return frameOpencvDnn,faceBoxes

parser=argparse.ArgumentParser()

parser.add_argument('--image')

args=parser.parse_args()

faceProto="opencv_face_detector.pbtxt"
faceModel="opencv_face_detector_uint8.pb"

ageProto="age_deploy.prototxt"

ageModel="age_net.caffemodel"

genderProto="gender_deploy.prototxt"

genderModel="gender_net.caffemodel"

MODEL_MEAN_VALUES=(78.4263377603, 87.7689143744,
114.895847746)

ageList=['(0-2)', '(4-6)', '(8-12)', '(15-20)', '(25-32)', '(38-43)', '(48-53)',


'(60-100)']

genderList=['Male','Female']

faceNet=cv2.dnn.readNet(faceModel,faceProto)

ageNet=cv2.dnn.readNet(ageModel,ageProto)

genderNet=cv2.dnn.readNet(genderModel,genderProto)

video=cv2.VideoCapture(args.image if args.image else 0)

padding=20
while cv2.waitKey(1)<0 :

hasFrame,frame=video.read()

if not hasFrame:

cv2.waitKey()

break

resultImg,faceBoxes=highlightFace(faceNet,frame)

if not faceBoxes:

print("No face detected")

for faceBox in faceBoxes:

face=frame[max(0,faceBox[1]-padding):

min(faceBox[3]+padding,frame.shape[0]-
1),max(0,faceBox[0]-padding)

:min(faceBox[2]+padding, frame.shape[1]-1)]

blob=cv2.dnn.blobFromImage(face, 1.0, (227,227),


MODEL_MEAN_VALUES, swapRB=False)
genderNet.setInput(blob)

genderPreds=genderNet.forward()

gender=genderList[genderPreds[0].argmax()]

print(f'Gender: {gender}')

ageNet.setInput(blob)

agePreds=ageNet.forward()

age=ageList[agePreds[0].argmax()]

print(f'Age: {age[1:-1]} years')

cv2.putText(resultImg, f'{gender}, {age}', (faceBox[0],


faceBox[1]-10), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0,255,255), 2,
cv2.LINE_AA)

cv2.imshow("Detecting age and gender", resultImg)

CHAPTER 8
TESTING

8.1 TESTING TECHNIQUES

Testing is a process of executing a program with the intent of


finding an error. A good test case is one that has a high probability of
finding an as-yet –undiscovered error. A successful test is one that
uncovers an as-yet- undiscovered error. System testing is the stage of
implementation, which is aimed at ensuring that the system works
accurately and efficiently as expected before live operation commences.
It verifies that the whole set of programs hang together. System testing
requires a test consists of several key activities and steps for run
program, string, system and is important in adopting a successful new
system. This is the last chance to detect and correct errors before the
system is installed for user acceptance testing.

The software testing process commences once the program is


created and the documentation and related data structures are designed.
Software testing is essential for correcting errors. Otherwise the program
or the project is not said to be complete. Software testing is the critical
element of software quality assurance and represents the ultimate the
review of specification design and coding. Testing is the process of
executing the program with the intent of finding the error. A good test
case design is one that as a probability of finding an yet undiscovered
error. A successful test is one that uncovers an yet undiscovered error.
Any engineering product can be tested in one of the two ways:

WHITE BOX TESTING

This testing is also called as Glass box testing. In this


testing, by knowing the specific functions that a product has been design
to perform test can be conducted that demonstrate each function is fully
operational at the same time searching for errors in each function. It is a
test case design method that uses the control structure of the procedural
design to derive test cases. Basis path testing is a white box testing.

Basis path testing:

 Flow graph notation


 Kilometric complexity
 Deriving test cases
 Graph matrices Control

BLACK BOX TESTING

In this testing by knowing the internal operation of a product, test can be


conducted to ensure that “all gears mesh”, that is the internal operation
performs according to specification and all internal components have
been adequately exercised. It fundamentally focuses on the functional
requirements of the software.

The steps involved in black box test case design are:

SOFTWARE TESTING STRATEGIES:

A software testing strategy provides a road map for the software


developer. Testing is a set activity that can be planned in advance and
conducted systematically. For this reason a template for software testing
a set of steps into which we can place specific test case design methods
should be strategy should have the following characteristics:

Testing begins at the module level and works “outward” toward the
integration of the entire computer based System.
CHAPTER 9

CONCLUSION

Artificial Intelligence systems have grown rapidly over the last years.
This enabled us to create, using multiple models and frameworks, a
system capable of detecting faces and classifying them by age and
gender. The main objective of this research work was to create an
efficient system that was able to detect faces in images and to classify
such faces into age and gender, and to evaluate wrong outputs in order to
find an underlying reason for such failures. In order to fulfill such
objective, various frameworks capable of detecting faces in images and
capable of classifying those into age and gender classes were tested and
validated in order to understand which would fit better into our problem.
APPENDIX

A.1 SCREENSHOTS
REFERENCE

[1] Yann LeCun, Yoshua Bengio & Geoffrey Hinton, “Deep Learning”,
2015, Nature Volume 521 p. 436–444. doi: 10.1038/nature14539

[2] Alex Krizhevsky, Ilya Sutskever & Geoffrey E. Hinton, “ImageNet


Classification with Deep Convolutional Neural Networks”, 2012, In
Proceedings of the International Conference on Neural Information
Processing Systems. doi: 10.1145/3065386

[3] Haoxiang Li, Zhe Lin, Xiaohui Shen, Jonathan Brandt & Gang Hua,
“A Convolutional Neural Network Cascade for Face Detection”, 2015,
In Proceedings of the IEEE Conference on Computer Vision and Pattern
Recognition p. 5325-5334. doi: 10.1109/CVPR.2015.7299170

[4] Shuo Yang, Ping Luo, Chen Change Loy & Xiaoou Tang, “From
Facial Parts Responses to Face Detection: A Deep Learning Approach”,
2015, In Proceedings of the IEEE International Conference on Computer
Vision p. 3676-3684. doi: 10.1109/ICCV.2015.419

[5] Sergey Ioffe & Christian Szegedy, “Batch Normalization:


Accelerating Deep Network Training by Reducing Internal Covariate
Shift”, 2015, Retrieved November 26, 2018 from:
https://arxiv.org/abs/1502.03167

[6] Sebastian Lapuschkin, Alexander Binder, Klaus-Robert Muller &


Wojciech Samek, “Understanding and Comparing Deep Neural
Networks for Age and Gender Classification”, 2017, In Proceedings of
the IEEE International Conference on Computer Vision p. 1629-1638.
doi: 10.1109/ICCVW.2017.191

[7] Xudong Suna, Pengcheng Wua & Steven C.H. Hoi, “Face detection
using deep learning: An improved faster RCNN approach”, 2018. doi:
10.1016/j.neucom.2018.03.030

[8] Shuo Yang, Yuanjun Xiong, Chen Change Loy & Xiaoou Tang,
“Face Detection through Scale-Friendly Deep Convolutional Networks”,
2017, Neurocomputing Volume 299 p.42-50

[9] Gil Levi & Tal Hassner, “Age and Gender Classification using
Convolutional Neural Networks”, 2015, In Proceedings of the IEEE
Conference on Computer Vision and Pattern Recognition p.34-42. doi:
10.1109/CVPRW.2015.7301352.

[10] Eran Eidinger, Roee Enbar & Tal Hassner , “Age and Gender
Estimation of Unfiltered Faces”, 2014, IEEE Transactions on
Information Forensics and Security Volume 9 p. 2127-2179. doi:
10.1109/TIFS.2014.2359646

[11] Afshin Dehghan, Enrique G. Ortiz, Guang Shu & Syed Zain
Masood, “DAGER: Deep Age, Gender and Emotion Recognition Using
Convolutional Neural Networks”, 2017, Retrieved December 3, 2018
[12] Rajeev Ranjan, Swami Sankaranarayanan, Carlos D. Castillo &
Rama Chellappa, “An All-InOne Convolutional Neural Network for
Face Analysis”, 2017, In Proceedings of the IEEE International
Conference on Automatic Face & Gesture Recognition. doi:
10.1109/FG.2017.137

[13] Grigory Antipov, Moez Baccouche, Sid-Ahmed Berrani, Jean-Luc


Dugelay, “Effective training of convolutional neural networks for face-
based gender and age prediction”, 2017, Pattern Recognition Volume 72
p.15-26. doi: 10.1016/j.patcog.2017.06.031

[14] Ujjwal Karn, “An Intuitive Explanation of Convolutional Neural


Networks”, 2016. Retrieved January 5, 2019 from:
https://ujjwalkarn.me/2016/08/11/intuitive-explanation-convnets/

[15] Tsun-Yi Yang, Yi-Hsuan Huang, Yen-Yu Lin, Pi-Cheng Hsiu &
Yung-Yu Chuang, “SSR- Net: A Compact Soft Stagewise Regression
Network for Age Estimation”, 2018, In Proceedings of the Twenty-
Seventh International Joint Conference on Artificial
Intelligence. doi: 10.24963/ijcai.2018/150

You might also like