Internship Report Final
Internship Report Final
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
CERTIFICATE
Date: 23/05/22
Place:Malegaon
3
Submitted By:
Submitted To:
Mr. Mayur Dev Sewak
General Manager, Operations Eisystems Services
&
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.
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
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:
Prerequisites:
We’ll need to install OpenCV (cv2) to be able to run this project. We can do this with pip-
Other packages we’ll be needing are math and argparse, but those come as part of the
standard Python library.
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
frameOpencvDnn=frame.copy()
frameHeight=frameOpencvDnn.shape[0]
frameWidth=frameOpencvDnn.shape[1]
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])
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"
genderList=['Male','Female']
faceNet=cv2.dnn.readNet(faceModel,faceProto)
ageNet=cv2.dnn.readNet(ageModel,ageProto)
genderNet=cv2.dnn.readNet(genderModel,genderProto)
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:
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)]
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()]
REFERENCES
[1] M. H. U. Yap, “Facial image processing for facial analysis,” Proceedings - International
Carnahan Conference on Security Technology., vol. 1, 2010.
[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.
[5] W.-Y. &. C. R. &. P. Zhao, “Face Recognition: A Literature Survey,” ACM Comput.
Surv.., pp. 399-458.
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"
genderList=['Male','Female']
faceNet=cv2.dnn.readNet(faceModel,faceProto)
ageNet=cv2.dnn.readNet(ageModel,ageProto)
genderNet=cv2.dnn.readNet(genderModel,genderProto)
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:
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)]
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()]
REFERENCES
[1] M. H. U. Yap, “Facial image processing for facial analysis,” Proceedings - International
Carnahan Conference on Security Technology., vol. 1, 2010.
[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.
[5] W.-Y. &. C. R. &. P. Zhao, “Face Recognition: A Literature Survey,” ACM Comput.
Surv.., pp. 399-458.