paint-brush
Building An Age Predictor Web App Using Deep Learningby@btahir
2,088 reads
2,088 reads

Building An Age Predictor Web App Using Deep Learning

by Bilal TahirNovember 20th, 2018
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

If you just want to play around with the app, check it out here: <a href="https://age-predictor.now.sh/" target="_blank">https://age-predictor.now.sh/</a>

Companies Mentioned

Mention Thumbnail
Mention Thumbnail
featured image - Building An Age Predictor Web App Using Deep Learning
Bilal Tahir HackerNoon profile picture

If you just want to play around with the app, check it out here: https://age-predictor.now.sh/

Continuing on my deep learning journey, I decided to take a stab at trying to predict ages of people in images.

Thankfully, there was a really nice dataset available for me to use called the IMDB-Wiki dataset: https://data.vision.ee.ethz.ch/cvl/rrothe/imdb-wiki/

Transfer Learning

I can’t harp on this enough. Transfer Learning is awesome! You can take an already trained model and go so much further without having to spend days training your model. It’s like a relay race where the original model is passing you the baton to keep going.

Using the Wikipedia Face-Only data, I trained a Resnet-50 Model (which was already trained on Imagenet). This was similar to the approach the people who created the dataset had taken but they used a different head i.e. VGG16 model instead of Resnet.

Wrestling With Data

Often times, getting the data into a nice digestible form is the hardest challenge of a deep learning project. Even though the data was there for me to consume in this case, I still had to do some wrangling.

Firstly, the data was divided into subsets and stored in folders numbered 01–99. I wrote a python script to loop through the directories and move all the files into one folder where my model would consume it.

An interesting challenge was to get the labels as there was no separate file for them but rather they were within the filenames of the images themselves. The images in the dataset had filenames that included the date of birth of the person and the year the picture was taken. Using these, and assuming a mid-year date of 7/1 for when the photo was taken, we can come up with a good estimate of the age of the person in the photo when it was taken.

I wrote another snippet of code to derive the age from these two dates to get the labels. To keep it simple for now, I selected only images from ages between 10–120. This means the model will not work for really young kids…or really really old people.

And now we have our data as well as the ages/labels:

Model Training

Time to train the model! I used the amazing fastai library which runs on Pytorch for my Deep Learning: https://github.com/fastai/fastai.

Fastai is a great way for new comers to get into Deep Learning. Find out more on their website and take their course. It’s Free!

Results

After a few hours of training, the Model didn’t look too bad:

Deploying To Production

I liked the results (and even if they were wrong that still sounded fun so…). I moved my model into a Zeit app codebase. Zeit is a great service for deploying your app quickly (and they have a free tier!): https://zeit.co/

And here is my live app: https://age-predictor.now.sh/

Here is the same example above in the app:

Not too shabby, despite the cheesy Alien Font

Please do play around with some photos and see what age predictions you get. Let me know how it goes!

Github Repo containing the code: https://github.com/btahir/age-detector