0% found this document useful (0 votes)
3 views17 pages

Internship Report Final

The report presents a project on age and gender detection using a Python algorithm and Deep Learning techniques. It outlines the methodology for classifying individuals based on facial images, detailing the requirements, procedures, and the use of Convolutional Neural Networks for processing. The project aims to simplify human classification for applications in various fields such as security and identification.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views17 pages

Internship Report Final

The report presents a project on age and gender detection using a Python algorithm and Deep Learning techniques. It outlines the methodology for classifying individuals based on facial images, detailing the requirements, procedures, and the use of Convolutional Neural Networks for processing. The project aims to simplify human classification for applications in various fields such as security and identification.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

A

REPORT
ON
Age And Gender Detection
SUBMITTED TO THE SAVITRIBAI PHULE PUNE UNIVERSITY, PUNE
IN PARTIAL FULFILLMENT OF THE REQUIREMENTS
FOR THE AWARDS OF THE DEGREE

THIRD YEAR BACHELOR OF ENGINEERING


Submitted by

Ansari Belal Ahmed Jamal Arif.


T191164206

MAULANA MUKHTAR AHMAD NADVI TECHNICAL CAMPUS


(MMANTC)
ABDUL LATIF ALI AL SHAYA FACULTY OF ENGINEERING AND
TECHNOLOGY
DEPARTMENT OF COMPUTER ENGINEERING
Academic Year 2021-22
SAVITRIBAI PHULE PUNE UNIVERSITY

CERTIFICATE

A Report entitled "Age And Gender Detection"


” Submitted by Ansari
Ansari Belal Ahmed Jamal Arif for the Partial fulfillment of the award of
Roll No.20
degree of Third Year of Computer Engineering is examined and certified.

Internal Examiner External Examiner/HOD

Date: 23/05/22

Place:Malegaon
3

Report on Gender and Age Detection

Submitted By:

Ansari Belal Ahmed Jamal Arif

Submitted To:
Mr. Mayur Dev Sewak
General Manager, Operations Eisystems Services

&

Data Science & Machine Learning Students


Ms. Mallika Srivastava
Trainer, Data Science & Analytics Domain Eisystems Services
4

Serial Number Title Page Number

1. Abstract 2

2. Objective 2

3. Introduction 2

4. Search Methodology 2

5. Procedure 3

6. Face Processing 3

7. Prerequisites 4

8. Input/Output 5

9. Screenshots 6

10. Code 7

11. References 10
5

Abstract

In this project, I worked on a technique for age and gender classification using python
algorithm. Human identification and classification are being utilized in various field for a
very long time. Fields like Government ID Cards, Verification procedures etc. We have
already developed techniques like retina scan, iris scans, fingerprint and other sophisticated
systems such as DNA fingerprinting to identify the individuals. Although these already built
methods works efficiently, the hardware, software and human proficiency requirement are
way too demanding for several simpler task which may or may not require a professional
efficiency. Technique reported in this paper is simple and easy for human classification
which can be performed using only a webcam and a decent computer system.

Gender and Age Detection - Objective:


To build a gender and age detector that can approximately guess the gender and age of the
person (face) in a picture using Deep Learning on the Adience dataset.

INTRODUCTION

Human Classification is an age-old procedure and being done in various fields and
technology such as biometrics, forensics sciences, Image processing, Identification
system, etc. With the development of Artificial Intelligence and techniques such as
Neural Network and Deep Learning, it has become increasingly easier to classify human.
These new technologies help identification, classification of Individuals without the need
of another professional or Individual records. Also Being immensely fast, these
technologies can classify millions of individuals way faster than a professional. Human
Facial Image Processing provides many clues and cues applicable to industries such as
security, entertainment, etc . Human Face can provide immense amount of information
like their emotional state, slightest agreement or disagreement, irony or anger, etc. This
is the reason why faces have been long research topic in psychology [2]. This data (or in
our case digital data) is very valuable as they help recognition, selection or identification
of individual according to the requirement. Age and Gender Detection can alone provide
a lot of information to places such as recruitment team of organizations, Verification of
ID cards, example: Voter ID cards which millions of individual uses to cast their vote at
the time of election, etc. Human Facial Image processing eases the task of finding
ineligible or counterfeit individuals.
6

RESEARCH METHODOLOGY

Basic requirement for this project includes: Python 2.7-3.6, Open CV2, PyCharm
Community Edition, Webcam (at least 2.0MP). An adequately equipped windows
machine to run the project is required. The Project uses Python Deep Learning to
identify the gender and age of given face data accurately. Deep Learning belongs to the
family of machine Learning. Deep Learning mimics the functionality of human cognitive
thinking and acts as an Artificial Intelligence system. It can recognise objects, faces,
speeches, characters from unstructured data sets. The Algorithm designed is divided
into four main parts: Input, Face Detection, Face Processing (Age and Gender
classification) and output.
7

PROCEDURE

Since the technique is implemented, we can start testing it for its accuracy. The general
procedure to be followed is

• Input the data.


• Create a frame.
• Detect the face.
• Classify the Gender.
• Classify the Age Group.
• Attach the result in the image.
• Output the image in specified location.

Face Processing

This process allows us to extract data from the detected face in previous step. Once the face
has been detected data can be extracted. here we are only testing and benchmarking the
gender and age of the faces but face can provide enough information to study emotion,
ethnicity, heritage, biasness such as agreement/disagreement, mood, abnormality. These
things are highly useful in various industries. Face is the most natural body part utilized for
biometrics application .

Once the face has been detected in the frame. We can start its processing using
Convolutional Neural Network or CNN. It is a type Deep Neural Network which is mostly
used for Image processing and NLP. The CNN will carry out the testing training phase and
will give different prediction. For Gender the prediction can be either of two: Male and
Female. Age estimation is a multi-class problem in which the years are classified into classes.
People with different ages have different facials, so it is difficult to gather the information
accurately [6]. To make the process faster we have created age groups. The Age prediction
can be either of these 8 groups: (0 – 2), (4 – 6), (8 – 12), (15 – 20), (25 – 32), (38 – 43), (48 –
53) and (60 – 100).

The Architecture here uses three convolutional layers each with different nodes and kernel
sizes, specifically:

• 96 nodes with kernel size of 7

• 256 nodes with kernel size of 5

• 384 nodes with kernel size of 3


8

Prerequisites:
We’ll need to install OpenCV (cv2) to be able to run this project. We can do this with pip-

1. pip install opencv-python

Other packages we’ll be needing are math and argparse, but those come as part of the
standard Python library.

Fig : Flow chart of algorithm

Fig: Flow chart of model


9

Input:

Main Focus of this design is to make the whole process easier and faster. In order to get the
input fast there are two options to feed the data into the algorithm. First, User can use the
system webcam or any other webcam camera device to directly take the live data. This is
not only fast but user can get real-time output while using the webcam device. Second User
can use “—image .jpg” tag while initiating the algorithm. This method reads the jpeg file,
process it and gives back the output. One key advantage of this method is user can process
multiple files at once.

Output:

It is the last part of the workflow. Here the Output is saved in .jpeg format if the input had image
sourced in it. If the webcam is used the output will be overlaid in the video output from the webcam.
If the face is not detected in input frame the “No Face is detected” will be shown as an output. And
no .jpeg output will be stored.
10

Screenshots
11

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
12

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:
13

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)


14

REFERENCES

[1] M. H. U. Yap, “Facial image processing for facial analysis,” Proceedings - International
Carnahan Conference on Security Technology., vol. 1, 2010.

[2] C. Y. Jiang X., Applied Pattern Recognition. Studies in Computational Intelligence,


Berlin, Heidelberg: Springer, 2008.

[3] D. J. K. a. N. A. M. H. Yang, “Detecting Faces in Images: A Survey,” IEEE, vol. 24, no. 1,
pp. 34-58, 2002.

[4] P. V. a. M. Jones, “Rapid object detection using a boosted cascade of simple


features,” Proceedings of the 2001 IEEE Computer Society Conference on Computer
Vision and Pattern Recognition, vol. 1, 2001.

[5] W.-Y. &. C. R. &. P. Zhao, “Face Recognition: A Literature Survey,” ACM Comput.
Surv.., pp. 399-458.

[6] K. K. Y. Kaya, “A BASIC STUDY ON HUMAN FACE RECOGNITION,” Frontiers of Pattern


Recognition, Academic Press, pp. 265-289, 1972.

[7] D. D. Zhang, “Automated Biometrics - Technologies and Systems,” Kluwer Academic


Publishers, vol. 1, 2000. [8] R. E. a. T. H. E. Eidinger, “Age and Gender Estimation of
Unfiltered Faces,” IEEE Transactions on Information Forensics and Security, vol. 9, no.
12, pp. 2170-2179, 2014.
8

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:
9

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)


10

REFERENCES

[1] M. H. U. Yap, “Facial image processing for facial analysis,” Proceedings - International
Carnahan Conference on Security Technology., vol. 1, 2010.

[2] C. Y. Jiang X., Applied Pattern Recognition. Studies in Computational Intelligence,


Berlin, Heidelberg: Springer, 2008.

[3] D. J. K. a. N. A. M. H. Yang, “Detecting Faces in Images: A Survey,” IEEE, vol. 24, no. 1,
pp. 34-58, 2002.

[4] P. V. a. M. Jones, “Rapid object detection using a boosted cascade of simple


features,” Proceedings of the 2001 IEEE Computer Society Conference on Computer
Vision and Pattern Recognition, vol. 1, 2001.

[5] W.-Y. &. C. R. &. P. Zhao, “Face Recognition: A Literature Survey,” ACM Comput.
Surv.., pp. 399-458.

[6] K. K. Y. Kaya, “A BASIC STUDY ON HUMAN FACE RECOGNITION,” Frontiers of Pattern


Recognition, Academic Press, pp. 265-289, 1972.

[7] D. D. Zhang, “Automated Biometrics - Technologies and Systems,” Kluwer Academic


Publishers, vol. 1, 2000. [8] R. E. a. T. H. E. Eidinger, “Age and Gender Estimation of
Unfiltered Faces,” IEEE Transactions on Information Forensics and Security, vol. 9, no.
12, pp. 2170-2179, 2014.

You might also like