SAVITRIBAI PHULE PUNE UNIVERSITY, PUNE
A
                 MINI PROJECT REPORT ON
      “Gender and Age Detection on UTKFace Dataset”
SUBMITTED TO THE SAVITRIBAI PHULE PUNE UNIVERSITY, PUNE IN
      THE FULFILLMENT OF THE REQUIREMENT OF
       DL Mini Project Final Year Computer Engineering
                  Academic Year 2024-25
                               BY
       Name of Student                         Roll No
      Abhijit Jagtap
                       Under The Guidance Of
                       Prof. Deepti V Sagade
  Department of Computer Engineering Navsahyadri Group of Institutes
                           Naigaon, Pune
                                  CERTIFICATE
                     This is to certify that mini project entitled,
               “Gender and Age Detection on UTKFace Dataset”
                                    Submitted by
               Name of student                                   Roll No
               Abhijit Jagtap
Is a bonafide work carried out by them under the supervision of Prof. Tushar D kolhe and
is approved for the partial fulfillment of the requirement of High Performance Computing
course in final Year Computer Engineering, in the academic year 2024-2025 prescribed
by Savitribai Phule Pune University, Pune.
Prof. D.V. Sagade                                               Prof. T. D. Kolhe
    Guide                                                      Head of Department ,
                                                               Computer Engineering
Place : Pune
Date :
                                  DECLARATION
I hereby declare that, the written submission represents my ideas in my own words and
where others' ideas or words have been included, I have adequately cited and referenced
the original sources. I also declare that I have adhered to all principles of academic
honesty and integrity and have not misrepresented or fabricated or falsified any
idea/data/fact/source in my submission. I understand that any violation of the above will
be cause for disciplinary action by the Institute and can also evoke penal action from the
sources which have thus not been properly cited or from whom proper permission has
not been taken when needed.
                               Name of students                       Signature
                                  Abhijit Jagtap
Date:
Place:
                          Acknowledgement
We are taking this opportunity to acknowledge each and every one who
contributed towards our work. We express our sincere gratitude towards guide
Prof. D.V. Sagade Professor at Navsahyadri Group of Institutes Faculty of
Engineering , Naigaon for his valuable inputs , guidance and support throughout
the course.
We wish to express our thanks to Prof.T.D.kolhe, Head of Computer Engineering
Department, Navsahyadri Group of Institutes Faculty of Engineering for giving
me all the help and important suggestions all over the work.
                               Name of students                    Signature
                                Abhijit Jagtap
                                      ABSTRACT
The aim of this project is to develop a deep learning-based system capable of accurately detecting
gender and estimating age from facial images using the UTKFace dataset. The UTKFace dataset
contains over 20,000 labeled images with annotations for age, gender, and ethnicity, making it a rich
resource for facial analysis tasks. The project utilizes Convolutional Neural Networks (CNNs), known
for their effectiveness in image processing, to extract and learn spatial features from facial images. A
hybrid model is designed to perform two tasks simultaneously: gender classification (binary) and age
estimation (regression). The system employs transfer learning by fine-tuning a pre-trained CNN model
to improve accuracy and reduce training time. Data preprocessing includes resizing images,
normalization, and data augmentation to enhance model generalization. The dataset is split into
training, validation, and test sets in an 80:10:10 ratio. The model is compiled with binary cross-entropy
and mean squared error (MSE) as loss functions for gender and age prediction respectively. Training is
conducted using Keras with real-time data generation. The model’s performance is evaluated using
accuracy for gender prediction and mean absolute error (MAE) for age estimation. The final model can
be deployed to predict gender and age from new facial images using OpenCV.
Project Title: Gender and Age Detection on UTKFace Dataset
Objective: The primary objective of this project is to design and implement a deep learning-based
system that can automatically detect an individual's gender and estimate their age from facial images
using the UTKFace dataset. This involves leveraging Convolutional Neural Networks (CNNs) to
extract meaningful features from facial data and predict two distinct outputs: a gender label
(male/female) and a continuous age value.
The project aims to address key challenges in computer vision, such as dealing with variations in
facial expressions, lighting conditions, image resolutions, and diverse ethnicities. Additionally, by
applying techniques like transfer learning, the model benefits from pre-trained weights to improve
performance and reduce training time.
Beyond achieving high accuracy and low prediction error, the project also seeks to build a scalable
and efficient pipeline from data preprocessing to real-time prediction that can be integrated into
applications such as biometric systems, demographic analytics, personalized content delivery, and
security systems.
Hardware Requirements:
   ● Multi-core CPU: Required for efficient data preprocessing and model training. A CPU with
      hyper-threading support is preferred.
   ● GPU (Optional but Recommended): A dedicated GPU (e.g., NVIDIA with CUDA support)
      significantly accelerates training time for deep learning models.
   ● RAM: At least 8 GB of RAM is recommended to handle the dataset and model operations
      smoothly. Higher RAM (16 GB or more) is beneficial for faster data loading and batch
      processing.
   ● Storage: Minimum 5 GB of free disk space to store the UTKFace dataset, model weights, logs,
      and intermediate results.
Software Requirements:
   ● Python: Programming language used for implementing the deep learning model.
   ● Keras: High-level neural networks API used to build and train the CNN model, running on top
      of TensorFlow.
   ● TensorFlow: Backend framework for Keras, providing tools for building and optimizing deep
      learning models.
   ● Jupyter Notebook / Any Python IDE: For writing, testing, and visualizing the code during
      development.
   ● NumPy and Pandas: For efficient data manipulation and numerical operations.
   ● Matplotlib / Seaborn: For visualizing data distributions and training progress (accuracy/loss
      curves).
   ● OpenCV (cv2): For loading and preprocessing new sample images for prediction.
   ● Scikit-learn: For additional utilities such as data splitting, metrics, and performance evaluation.
Theory:
In the context of gender and age detection, deep learning theory forms the foundation for developing
accurate and efficient models that can automatically learn meaningful representations from raw data
(such as facial images) without the need for manual feature engineering.
Here's a breakdown of key concepts in deep learning theory relevant to this project:
   ● Neural Networks: Deep learning relies on artificial neural networks (ANNs), which are
      computational models inspired by the biological neural networks in the human brain. ANNs
      consist of interconnected layers of artificial neurons (nodes), each performing simple
      mathematical operations on input data and passing the result to the next layer.
   ● Convolutional Neural Networks (CNNs): CNNs are a type of neural network particularly
      well-suited for processing grid-like data, such as images. They are composed of convolutional
      layers, pooling layers, and fully connected layers. Convolutional layers apply convolution
      operations to input images, extracting spatial hierarchies of features through learned filters.
      Pooling layers downsample feature maps, reducing computational complexity and promoting
      translation invariance. Fully connected layers combine extracted features to make predictions.
   ● Transfer Learning: Transfer learning is a technique where pre-trained models developed for one
      task are reused as the starting point for a new task. In gender and age detection, transfer learning
      allows leveraging pre-trained CNN models (trained on large datasets like ImageNet) to extract
      generic facial features, which can then be fine-tuned for the specific tasks of gender
      classification and age estimation.
   ● Activation Functions: Activation functions introduce non-linearity into neural networks,
      enabling them to learn complex mappings between inputs and outputs. Common activation
      functions include ReLU (Rectified Linear Unit), sigmoid, and softmax. ReLU is typically used
      in hidden layers of CNNs for its computational efficiency and ability to mitigate the vanishing
      gradient problem.
   ● Backpropagation: Backpropagation is a key algorithm used to train neural networks by
      iteratively adjusting model parameters to minimize a specified loss function. It involves
      computing gradients of the loss function with respect to each parameter using the chain rule of
      calculus and updating parameters in the direction that reduces the loss.
   ● Optimization Algorithms: Optimization algorithms determine how model parameters are
      updated during training to minimize the loss function. Common optimization algorithms include
      stochastic gradient descent (SGD), Adam, RMSprop, and AdaGrad.
   ● Loss Functions: Loss functions quantify the difference between predicted outputs and ground
      truth labels, providing feedback signals used during training. In classification tasks like gender
      detection, categorical cross-entropy loss is often used. In regression tasks like age estimation,
      mean squared error (MSE) or mean absolute error (MAE) are commonly employed.
Methodology:
Dataset Collection and Preparation: Utilize the UTKFace dataset, which includes facial images
accompanied by gender and age labels. Preprocess the images to a uniform size, shuffle the dataset,
and cap ages at 100 years for consistency.
Dataset Splitting: Divide the dataset into training, validation, and testing sets with a typical ratio of
80%, 10%, and 10%, respectively.
Data Generators: Implement data generators for the training, validation, and testing sets using Keras's
ImageDataGenerator class. Employ data augmentation techniques like rotation, zoom, and horizontal
flipping to enhance model robustness.
Model Architecture: Design a convolutional neural network (CNN) that inputs face images and
outputs two values: the probability of the subject being male and their predicted age. Incorporate
multiple convolutional and pooling layers, followed by dense layers.
Model Compilation: Compile the model with binary cross-entropy loss for the gender classification
and mean squared error (MSE) for age prediction. Select appropriate metrics such as accuracy for
gender and mean absolute error (MAE) for age.
Model Training: Train the model using the fit method, providing the data generators for training and
validation sets, specifying the number of epochs and batch size.
Model Evaluation: Assess the model on the testing set using the evaluate method to determine
accuracy and MAE.
Prediction: To predict gender and age for a new sample image, use the OpenCV library (cv2) to load
and preprocess the image (resize and normalize). Employ the model's predict method to obtain
predictions.
Code:
Detect.py
Output:
Conclusion:
This project successfully demonstrates the application of deep learning techniques for dual-purpose
facial analysis gender classification and age estimation using the UTKFace dataset. By leveraging
Convolutional Neural Networks (CNNs) and the concept of transfer learning, the model is capable of
learning complex patterns and features from facial images, leading to accurate and reliable
predictions.
Through systematic preprocessing, data augmentation, and proper model architecture design, the
project handles challenges such as image variability, class imbalance, and overfitting. The use of
distinct loss functions for each output binary cross-entropy for gender and mean squared error for age
ensures effective multi-task learning. The evaluation metrics reflect strong model performance, with
high classification accuracy for gender and low mean absolute error (MAE) for age prediction.
Furthermore, the project showcases the practical integration of computer vision and deep learning in
real-world scenarios, such as surveillance systems, customer profiling, and personalized applications.
It also provides a scalable framework that can be extended to include other facial attributes, such as
emotion or ethnicity, or be deployed in mobile and web-based environments.
In summary, the project not only fulfills its technical objectives but also contributes to the growing
field of intelligent facial recognition systems, highlighting the potential of AI-driven solutions in
biometric analysis.