This repository presents a deep learning-based Age Estimation system implemented with PyTorch. The goal of this project is to accurately predict human age from facial images using convolutional neural networks (CNNs) Model (Resnet50).
Age estimation is a challenging computer vision task due to variations in lighting, pose, ethnicity, and facial attributes ([GitHub][1]). This project addresses these challenges by leveraging multiple large-scale datasets and modern deep learning techniques.
- 🧠 Deep learning-based age prediction using PyTorch
- 📊 Support for multiple benchmark datasets
- 🔄 End-to-end pipeline: preprocessing, training, evaluation
- 🧩 Modular and extensible code structure
- ⚡ Easy experimentation with different models and parameters
This project utilizes several widely-used datasets for age estimation:
- IMDB Dataset – Large-scale dataset of celebrity faces
- WIKI Dataset – Companion dataset with labeled age data
- UTKFace Dataset – Diverse dataset with age, gender, and ethnicity labels
- Morph II Dataset – High-quality longitudinal face dataset
📥 Note: Datasets are not included in this repository due to size limitations. Please download them manually and organize them according to the expected directory structure.
.
├── image/
├── models/
├── age_estimation.ipynb
├── requirements.txt # Dependencies
└── README.md
- A YOLOv8 face detection model (
yolov8n-face.pt) is used to detect faces. - For each image, the largest detected face is selected and expanded by a margin (default 20%).
- Cropped faces are saved to
cropped_faces/with a unique filename based on the original path.
- Images with dimensions smaller than 100×100 pixels are filtered out.
- Age values outside the range [1, 80] are removed.
- For UTKFace, gender and ethnicity are also extracted.
- Exploratory visualizations (histograms, violin plots, random sample grids) are generated.
- Base model: ResNet50 pre-trained on ImageNet, with the final fully connected layer replaced by a single neuron for age regression.
- Loss function: Mean Squared Error (MSE)
- Optimizer: Adamw
- Evaluation metric: Mean Absolute Error (MAE)
- The training loop uses
AverageMeterto track loss and metric over epochs.
- The trained model can be used to predict age on new images.
- Optionally, face detection is applied before feeding the cropped face to the model.
- A helper function
inference()returns the predicted age and the cropped PIL image.
Clone the repository:
git clone https://github.com/BehradFM/Age-estimation.git
cd Age-estimationrequired packages:
pip install -r requirements.txtDatasets:
The project is based on Convolutional Neural Networks (CNNs), which are widely used for image-based tasks such as age estimation. These models learn hierarchical facial features to estimate age effectively.
The age estimation model is trained using a staged transfer learning approach. We start from a ResNet50 model pre‑trained on ImageNet and progressively fine‑tune it on increasingly larger and more diverse face datasets. This strategy allows the model to first learn general facial features and then adapt to the specific task of age regression.
The IMDB‑Wiki dataset is large but contains noisy labels (ages estimated from birth and photo dates). We first train the model on IMDB for 15 epochs with a relatively high learning rate (1e-3) to quickly adapt the pre‑trained features to facial age patterns. Then, we continue training on Wiki for 30 epochs with a much lower learning rate (1e-5). The lower LR on Wiki helps refine the model without overfitting to the smaller, cleaner dataset.
UTKFace provides high‑quality age labels (directly annotated) and a balanced age distribution. We load the model trained on Wiki and fine‑tune it on UTKFace for 50 epochs with an even smaller learning rate (1e-5). This allows the model to specialize on precise age regression while preserving previously learned representations.
Finally, we combine all training data (IMDB, Wiki, UTKFace) and perform a final fine‑tuning for 30 epochs with a tiny learning rate (5e-6). This stage harmonises the model across all datasets, reducing domain‑specific biases and improving generalisation.
Across all stages, we use:
- Loss function: Mean Absolute Error (MAE) .
- Optimizer: Adamw with weight decay (
1e-4) to prevent overfitting.
This staged curriculum mimics a coarse‑to‑fine learning schedule and yields a robust age estimator.
| Dataset | Learning Rate (LR) | Weight Decay (WD) | Epochs |
|---|---|---|---|
| IMDB | 1e-3 | 1e-4 | 15 |
| Wiki | 1e-5 | 1e-4 | 30 |
| UTKFace | 1e-5 | 1e-4 | 50 |
| Final (All) | 5e-6 | 1e-4 | 30 |
All trainings use the same Adam optimizer and MSE loss. The final model is the one fine‑tuned on the combined dataset.
The performance of the model is evaluated using:
- Mean Absolute Error (MAE) – measures prediction accuracy
- Accuracy (optional) – for age group classification
You can configure key hyperparameters via command-line arguments:
- Learning rate
- Batch size
- Number of epochs
- Dataset selection
Contributions are welcome!
- Fork the repository
- Create a new branch
- Commit your changes
- Open a Pull Request
This project is released under the MIT License.
If you have any questions, suggestions, or issues, feel free to open an issue in the repository.
- IMDB-WIKI dataset creators
- UTKFace dataset
- Morph II dataset
- Open-source deep learning community
💡 If you find this project useful, consider giving it a ⭐ on GitHub!