Latest news about Bitcoin and all cryptocurrencies. Your daily crypto news habit.
Building An Age Prediction App Using Deep Learning
An App that predicts the age of the person in the photo
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
Building An Age Predictor Web App Using Deep Learning was originally published in Hacker Noon on Medium, where people are continuing the conversation by highlighting and responding to this story.
Disclaimer
The views and opinions expressed in this article are solely those of the authors and do not reflect the views of Bitcoin Insider. Every investment and trading move involves risk - this is especially true for cryptocurrencies given their volatility. We strongly advise our readers to conduct their own research when making a decision.