A deep learning project that predicts a person's age from facial images using a custom convolutional neural network (CNN).
This application leverages PyTorch and OpenCV for image processing and inference, trained on the UTKFace dataset.
- Custom CNN Architecture: Implements
FAPNet, a tailored CNN designed for facial age estimation. - Human-Level Accuracy: Achieves a Mean Absolute Error (MAE) of 5.08 (train) and 5.16 (validation) — matching human-level performance.
- Trained on UTKFace: A diverse and widely used dataset for facial age prediction.
- Image Preprocessing: Uses OpenCV for robust face detection and image normalization.
- Interactive Notebooks: Includes Jupyter notebooks for exploration, training, and evaluation.
- App Interface: Easy-to-use interface for real-time prediction from uploaded images.
- Python 3.10+
- pip
- Clone the Repository:
git clone https://github.com/zakariaelaoufi/Face-Age-Prediction.git
cd Face-Age-Prediction- Create a Virtual Environment (optional):
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate- Install Dependencies:
pip install -r requirements.txtpython app.pyUpload a facial image and receive the predicted age in real time.
jupyter notebookExplore the core logic in:
Face_Age_Prediction.ipynbsample.ipynb
Face-Age-Prediction/
├── .devcontainer/ # Dev container config
├── .idea/ # IDE configs
├── data/ # UTKFace dataset (not included by default)
├── models/ # Trained model checkpoints
├── Face_Age_Prediction.ipynb # Main notebook
├── sample.ipynb # Sample testing notebook
├── app.py # Streamlit or Flask app (if applicable)
├── fapnet.py # Custom CNN model
├── image_processing.py # Preprocessing utilities
├── requirements.txt # Python dependencies
├── runtime.txt # Runtime configuration
├── README.md # Project documentation
└── tetststts.jpg # Sample test imageFAPNet is a lightweight yet effective CNN designed for age regression.
It processes grayscale facial inputs and outputs a single scalar — the predicted age.
Trained using MSE loss, with a fine-tuned architecture for optimal bias-variance balance.
| Metric | Value |
|---|---|
| Train MAE | 5.08 |
| Validation MAE | 5.16 |
These results are comparable to human-level age estimation accuracy.
The model is trained on the UTKFace dataset, a large-scale face dataset labeled by age, gender, and ethnicity. It contains over 20,000 images covering a wide age range (0–116 years), with diversity in ethnicity and gender.
Note: The dataset is not included in this repository. Please download it separately and place it in the data/ directory.
Contributions are welcome!
If you find a bug, want to suggest an improvement, or add a new feature, feel free to fork this repository and submit a pull request.
- Fork the repository
- Create a new branch:
git checkout -b feature-name - Commit your changes:
git commit -m 'Add new feature' - Push to the branch:
git push origin feature-name - Open a pull request
Feel free to use and modify it for personal or commercial use.
- UTKFace Dataset by Zhang et al.
- PyTorch and OpenCV
- Open-source ML research community
Made by Zakaria Elaoufi