Final Documentation 9
Final Documentation 9
CHAPTER 1
INTRODUCTION
that are appropriate for a patient's age and gender. Security: Age and
gender detection technologies are used in security systems to improve
accuracy and efficiency. For example, facial recognition technology
can be used to identify potential threats or suspects. Entertainment:
Age and gender detection technologies are used in the entertainment
industry to provide personalized experiences to users. For example,
streaming platforms can use this information to suggest content that
is tailored to a user's age and gender. Overall, age and gender
detection technologies are used to gather information and provide
personalized experiences in various fields, from marketing to
healthcare to security.
MOTIVATION:
CHAPTER 2
LITERATURE SURVEY
CHAPTER 3
SYSTEM ANALYSIS
The Face API uses machine learning models to analyze facial features
such as the distance between the eyes, the shape of the nose and
mouth, and the texture of the skin to estimate age and gender. The
age estimation feature returns a range of ages, while the gender
estimation feature returns either male or female.
For age estimation, the Face API returns a range of ages rather than a
specific age, since age estimation based on facial features is not a
precise science. The age range is typically divided into five-year
increments, for example, "18-24", "25-29", and so on.
The Face API can be easily integrated into web or mobile applications,
making it accessible to developers who want to add age and gender
detection features to their projects without having to build the models
from scratch. Microsoft Azure also provides tools for customizing and
training the Face API models to improve their accuracy and
performance for specific use cases.
about the true positive, false positive, true negative, and false negative
rates of the system.
The proposed system for age and gender recognition using the
Caffe library consists of three main components: data collection,
feature extraction, and model training. The system can be evaluated
using metrics such as precision, recall, and F1-score. The accuracy of
the system can be improved by using larger datasets, better feature
extraction techniques, and more advanced machine learning
algorithms. The proposed system has wide applications in areas such
as security, marketing, healthcare, and entertainment.
13
CHAPTER 4
FEASIBILITY STUDY
• Tool : PyCharm
CHAPTER 5
SYSTEM DESIGN
LAYERS OF CNN
3. Activation Layer
4. Fully Connected Layer
5. Dropout Layer
6. Batch Normalization Layer
1. CONVOLUTIONAL LAYER
2. POOLING LAYER
3. ACTIVATION LAYER
f(x) = max(0, x)
where x is the input tensor. In other words, ReLU sets any negative
value in the input tensor to zero and leaves any positive value
23
f(x) = 1 / (1 + e^(-x))
5. DROPOUT LAYER
Scaling and Shifting: The normalized activations are then scaled and
shifted using learnable parameters. This allows the network to learn
the optimal scale and shift for each activation.
5.3 Cascade
To use these cascade classifiers in your Python code, you can load the
XML file using the CascadeClassifier class provided by OpenCV, and
then use the detectMultiScale function to detect the target feature
(age or gender) in the image.
30
Advantages:
Overall, cascade classifiers are a useful technique for age and gender
detection in images, especially in applications where speed and
efficiency are critical. While they may not be as accurate as other
techniques in all cases, they are a good option to consider when
designing image-based application.
31
LAYERS OF DNN
1. Input Layer
2. Hidden Layer
3. Output Layer
1. INPUT LAYER
The input layer is the first layer of a deep neural network (DNN)
that receives the input data. It is responsible for transforming the raw
input data into a format that can be processed by the network. The
number of nodes in the input layer corresponds to the number of
input features or variables in the data.
2. HIDDEN LAYER
3. OUTPUT LAYER
top-1 and top-5 error rates of 15.3% and 7.4%, respectively, in the
2014 competition.
5.6 deploy_gender.prototxt
The pooling layers are used to reduce the size of the feature maps and
make the network more computationally efficient. These layers
perform a non-linear down-sampling operation, which reduces the
spatial dimensions of the input.
5.7 gender_net.caffemodel
5.8 deploy.prototxt
5.9 res10_300x300_ssd_iter_140000_fp16.caffemodel
Res10_300x300_ssd_iter_140000_fp16.caffemodel is a deep
learning model that is widely used for object detection. It is a part of
the Single Shot Multibox Detector (SSD) architecture and was trained
on the COCO (Common Objects in Context) dataset. This essay will
discuss the Res10_300x300_ssd_iter_140000_fp16.caffemodel model,
its architecture, and its applications.
5.10 deploy_age.prototxt
saves time and effort and makes the deployment process more
efficient.
5.11 age_net.caffemodel
5.12 NUMPY
CHAPTER 6
IMPLEMENTATION
6.1 MODULES:
User
Application
Face detection with Haar cascades
Gender Recognition with CNN
Age Recognition with CNN
MODULES DESCRIPTION:
User
Human who gives a frame/video to detect gender and predict age.
APPLICATION
CHAPTER-7
RESULT
The given code is a Python script for predicting the age and
gender of faces in images or from a live webcam feed using pre-trained
deep learning models. Here's an explanation of the code:
The code begins by importing necessary libraries: `cv2` for computer
vision tasks, `numpy` for numerical operations, and `argparse` for
command-line argument parsing.
The script defines various constants: - `FACE_PROTO` and
`FACE_MODEL`: Paths to the prototxt file and pre-trained model file
for face detection. - `GENDER_MODEL` and `GENDER_PROTO`: Paths
to the prototxt file and pre-trained model file for gender classification.
- `AGE_MODEL` and `AGE_PROTO`: Paths to the prototxt file and pre-
trained model file for age estimation. - `MODEL_MEAN_VALUES`:
Mean values used for preprocessing the input image. -
`GENDER_LIST`: List of gender labels ('Male' and 'Female'). -
`AGE_INTERVALS`: List of age intervals.
The script defines the `frame_width` and `frame_height` variables,
which specify the desired width and height of the processed frames.
57
CHAPTER 8
ADVANTAGES
5. Better data analysis: Age and gender prediction models can help
companies analyze their customer data more effectively
60
CHAPTER 9
CONCLUSION
CHAPTER 10
FUTURE ENHANCEMENT
BIBLIOGRAPHY
[9] P. Smith and C. Chen, ‘‘Transfer learning with deep CNNs for
gender recognition and age estimation,’’ in Proc. IEEE Int. Conf. Big
Data (Big Data), Dec. 2018, pp. 2564–2571. [38] N. Srinivas, H. Atwal,
D. C. Rose, G. Mahalingam, K. Ricanek, and D. S. Bolme, ‘‘Age,
gender, and fine-grained ethnicity prediction using convolutional
neural networks for the East Asian face dataset,’’ in Proc. 12th IEEE
Int. Conf. Autom. Face Gesture Recognit. (FG), May 2017, pp. 953–
960, doi: 10.1109/FG.2017.118.
[10] R. K. Srivastava, K. Greff, and J. Schmidhuber, ‘‘Training very
deep networks,’’ in Proc. Adv. Neural Inf. Process. Syst., 2015, pp.
2377–2385.
[11] P. Viola and M. J. Jones, ‘‘Robust real-time face detection,’’ Int.
J. Comput. Vis., vol. 57, no. 2, pp. 137–154, May 2004. [41] F. Wang,
M. Jiang, C. Qian, S. Yang, C. Li, H. Zhang, X. Wang, and X. Tang,
‘‘Residual attention network for image classification,’’ in Proc. IEEE
Conf. Comput. Vis. Pattern Recognit. (CVPR), Jul. 2017, pp. 3156–
3164.
[12] X. Wang, R. Guo, and C. Kambhamettu, ‘‘Deeply-learned feature
for age estimation,’’ in Proc. IEEE Winter Conf. Appl. Comput. Vis.,
Jan. 2015, pp. 534–541.
[13] M. Xia, X. Zhang, L. Weng, and Y. Xu, ‘‘Multi-stage feature
constraints learning for age estimation,’’ IEEE Trans. Inf. Forensics
Security, vol. 15, pp. 2417–2428, 2020, doi:
10.1109/TIFS.2020.2969552.
[14] S. Xie, R. Girshick, P. Dollár, Z. Tu, and K. He, ‘‘Aggregated
residual transformations for deep neural networks,’’ in Proc. IEEE
Conf. Comput. Vis. Pattern Recognit. (CVPR), Jul. 2017, pp. 1492–
1500.
[15] K. Zhang, C. Gao, L. Guo, M. Sun, X. Yuan, T. X. Han, Z. Zhao,
and B. Li, ‘‘Age group and gender estimation in the wild with deep RoR
architecture,’’ IEEE Access, vol. 5, pp. 22492–22503, 2017, doi:
10.1109/ACCESS.2017.2761849. 85688 VOLUME 9, 2021 A.
[16] R. Rothe, R. Timofte, and L. V. Gool, ‘‘DEX: Deep EXpectation of
64
apparent age from a single image,’’ in Proc. IEEE Int. Conf. Comput.
Vis. Workshop (ICCVW), Dec. 2015, pp. 10–15.
[17] R. Rothe, R. Timofte, and L. Van Gool, ‘‘Deep expectation of real
and apparent age from a single image without facial landmarks,’’ Int.
J. Comput. Vis., vol. 126, nos. 2–4, pp. 144–157, Apr. 2018.
[18] W. Samek, A. Binder, S. Lapuschkin, and K.-R. Müller,
‘‘Understanding and comparing deep neural networks for age and
gender classification,’’ in Proc. IEEE Int. Conf. Comput. Vis.
Workshops (ICCVW), Oct. 2017, pp. 1629–1638.
[19] C. Sammut and G. I. Webb, Eds., ‘‘Mean absolute error,’’ in
Encyclopedia of Machine Learning. Boston, MA, USA: Springer, 2010,
p. 652, doi: 10.1007/978-0-387-30164-8_525.
[19] A. V. Savchenko, ‘‘Efficient facial representations for age, gender
and identity recognition in organizing photo albums using multi-
output ConvNet,’’ PeerJ Comput. Sci., vol. 5, p. e197, Jun. 2019, doi:
10.7717/peerj-cs.197.
[20] P. Smith and C. Chen, ‘‘Transfer learning with deep CNNs for
gender recognition and age estimation,’’ in Proc. IEEE Int. Conf. Big
Data (Big Data), Dec. 2018, pp. 2564–2571.
[21] N. Srinivas, H. Atwal, D. C. Rose, G. Mahalingam, K. Ricanek,
and D. S. Bolme, ‘‘Age, gender, and fine-grained ethnicity prediction
using convolutional neural networks for the East Asian face dataset,’’
in Proc. 12th IEEE Int. Conf. Autom. Face Gesture Recognit. (FG),
May 2017, pp. 953–960, doi: 10.1109/FG.2017.118.
[22] R. K. Srivastava, K. Greff, and J. Schmidhuber, ‘‘Training very
deep networks,’’ in Proc. Adv. Neural Inf. Process. Syst., 2015, pp.
2377–2385.
[23] P. Viola and M. J. Jones, ‘‘Robust real-time face detection,’’ Int. J.
Comput. Vis., vol. 57, no. 2, pp. 137–154, May 2004.
[24] F. Wang, M. Jiang, C. Qian, S. Yang, C. Li, H. Zhang, X. Wang,
and X. Tang, ‘‘Residual attention network for image classification,’’ in
Proc. IEEE Conf. Comput. Vis. Pattern Recognit. (CVPR), Jul. 2017,
pp. 3156–3164.
65
APPENDIX
import cv2
import numpy as np
GENDER_MODEL = 'deploy_gender.prototxt'
GENDER_PROTO = 'gender_net.caffemodel'
FACE_PROTO = "deploy.prototxt"
FACE_MODEL = "res10_300x300_ssd_iter_140000_fp16.caffemodel"
AGE_MODEL = 'deploy_age.prototxt'
AGE_PROTO = 'age_net.caffemodel'
AGE_INTERVALS = ['(0, 2)', '(4, 6)', '(8, 12)', '(15, 20)','(21, 24)', '(25,
32)', '(38, 43)', '(48, 53)', '(60, 100)']
frame_width = 1280
frame_height = 720
faces = []
for i in range(output.shape[0]):
confidence = output[i, 2]
if confidence > confidence_threshold:
box = output[i, 3:7] * \
np.array([frame.shape[1], frame.shape[0],
67
frame.shape[1], frame.shape[0]])
if width is None:
r = height / float(h)
dim = (int(w * r), height)
# otherwise, the height is None
else:
# calculate the ratio of the width and construct the
# dimensions
r = width / float(w)
dim = (width, int(h * r))
# resize the image
return cv2.resize(image, dim, interpolation = inter)
def get_gender_predictions(face_img):
blob = cv2.dnn.blobFromImage(
image=face_img, scalefactor=1.0, size=(227, 227),
mean=MODEL_MEAN_VALUES, swapRB=False, crop=False
)
gender_net.setInput(blob)
return gender_net.forward()
68
def get_age_predictions(face_img):
blob = cv2.dnn.blobFromImage(
image=face_img, scalefactor=1.0, size=(227, 227),
mean=MODEL_MEAN_VALUES, swapRB=False
)
age_net.setInput(blob)
return age_net.forward()
def predict_age_and_gender():
"""Predict the gender of the faces showing in the image"""
# create a new cam object
cap = cv2.VideoCapture(0)
while True:
_, img = cap.read()
# Take a copy of the initial image and resize it
frame = img.copy()
# resize if higher than frame_width
if frame.shape[1] > frame_width:
frame = image_resize(frame, width=frame_width)
# predict the faces
faces = get_faces(frame)
# Loop over the faces detected
# for idx, face in enumerate(faces):
for i, (start_x, start_y, end_x, end_y) in enumerate(faces):
face_img = frame[start_y: end_y, start_x: end_x]
# predict age
age_preds = get_age_predictions(face_img)
# predict gender
gender_preds = get_gender_predictions(face_img)
i = gender_preds[0].argmax()
gender = GENDER_LIST[i]
gender_confidence_score = gender_preds[0][i]
i = age_preds[0].argmax()
age = AGE_INTERVALS[i]
age_confidence_score = age_preds[0][i]
# Draw the box
label = f"{gender}-{gender_confidence_score*100:.1f}%, {age}-
{age_confidence_score*100:.1f}%"
# label = "{}-{:.2f}%".format(gender,
gender_confidence_score*100)
#print(label)
69
yPos = start_y - 15
while yPos < 15:
yPos += 15
box_color = (255, 0, 0) if gender == "Male" else (147, 20, 255)
cv2.rectangle(frame, (start_x, start_y), (end_x, end_y),
box_color, 2)
# Label processed image
cv2.putText(frame, label, (start_x, yPos),
cv2.FONT_HERSHEY_SIMPLEX, 0.54, box_color, 2)
cv2.destroyAllWindows()
if __name__ == "__main__":
predict_age_and_gender()