Master LLMs with our FREE course in collaboration with Activeloop & Intel Disruptor Initiative. Join now!

Publication

Using a CNN to Classify Age Groups
Latest   Machine Learning

Using a CNN to Classify Age Groups

Last Updated on July 24, 2023 by Editorial Team

Author(s): Atiar Rahman

Originally published on Towards AI.

Diving Into my First Convolutional Neural Network U+007C Towards AI

Having recently learned about convolutional neural networks, I wanted to build my own. Initially, I wanted to be able to get a person’s age just from a picture of their face. However, this comes with its own challenges such as class imbalance and the amount of training time that would be necessary felt daunting. So I decided to make the problem easier by classifying people into age groups instead.

The biggest challenge with any machine learning project is getting labeled data. Luckily enough a similar project was done recently by the Computer Vision Lab at ETH Zurich. They created a data set by scraping images from IMDB and Wikipedia. The images were also cropped to mostly show faces only! The data set includes photos of actors and when the picture was taken allowing one to deduce their age at the time of the photo. Altogether, the original data set contains 524,230 images. After some exploratory data analysis and cleaning, I settled on using 85,565 images to reduce the computational load of the project and to match my needs in terms of class balance. My goal was to classify images into thirteen possible age groups that range from age 10 to age 80 in increments of five.

Building The Network U+007C Transfer Learning

For the CNN, transfer learning was used by using VGG-16’s convolutional base. Transfer learning is when you utilize the weights of a previously trained network in a new network. VGG-16 is a famous CNN that was trained on ImageNet which is a data set of over 14 million images belonging to 1000 classes. The model itself achieved 92.5% accuracy on these images. It originally classified images into 1000 different classes, but in this case, the top layers were changed so that it can classify face images into the 13 classes or age groups. This is why transfer learning is so beneficial because you don’t have to retrain your network which can be time-consuming and difficult depending on the resources you have available. Instead of retraining, you can build your network by training on top of a robust network. The full VGG-16 architecture can be seen in the image below.

VGG-16 Network Architecture

My model uses the same convolutional base as VGG-16 but has different fully connected layers and softmax layers that will classify images into 13 age groups. Only these layers were trained while the previous layers where left untrained. Instead, these layers are using the weights from when VGG-16 was trained on Image-Net.

Results

The model was trained on 59,110 images with the remaining images that were used for testing and validation. Due to time constraints, the model was trained up to 64% training accuracy. However, the testing and validation accuracy never went beyond 17%. I also created a function to return the three most probable age groups that a person belongs to. This function, the CNN, data cleaning, and exploratory data analysis can be seen on my GitHub.

AR3441/AgeClassificationFromFace

The goal of this project is to be able to classify age ranges by using a convolutional neural network that is trained…

github.com

Resources

For those interested in seeing a CNN that classifies faces into ages and not just age groups, I suggest the following paper by the Computer Vision Lab at ETH Zurich.

Join thousands of data leaders on the AI newsletter. Join over 80,000 subscribers and keep up to date with the latest developments in AI. From research to projects and ideas. If you are building an AI startup, an AI-related product, or a service, we invite you to consider becoming a sponsor.

Published via Towards AI

Feedback ↓