Skip to main content

Most of us use AWS for work, but you can us it for fun too! In this post we are going to look at one of AWS’s Artificial Intelligence (AI) product offering – Rekognition.
Rekognition is a fully-managed service for image analyses. It can detect objects, scenes, and faces in images. You can even catalog the faces and then search through the pictures for the person you are looking for. Amazon uses its vast data store of images (which is why they allow you to save unlimited pictures if you have Prime) to train and improve the processing all the time, and the results are astounding. It can detect emotion, sunglasses, gender and even estimated age range of the person in the photo.
So let’s have some fun: Let’s get the profile photos of the Linux Academy team members and let Rekognition estimate their age. Now, unlike most ‘tech’ companies, we actually have female team members and I know better to bring up the age topic with a lady so we are going to make sure that we do not scan their images.
First thing we need to get the images off the About page at This is where Google Chrome comes in handy. Just do “Right-Click” and “Inspect” on a picture…
… and Chrome opens up the HTML behind the page and we can see that the div individual-photo contains the like to person’s image, name and other details
Here we can write a quick and dirty Python script to pull down the images and the details down using BeautifulSoup.
Next is the Rekognition magic. Rekognition allows you the send the file as blobs or it can work on files in S3. For this example, I am going to upload the files into S3 and have it process them and parse through the returned JSON for the sex and age range of the person in the picture.

 # Call Rekognition API to detect faces
 json_data = img_client.detect_faces(
       'Bucket': 'blog-recog',
       'Name': filename
     Attributes=[ 'ALL' ]
# If a face was found
if json_data.get('FaceDetails',0):
    # if the face was a guy
    if json_data['FaceDetails'][0]['Gender']['Value'] == "Male":
        # parse the json for the age range
        print ' to '.join(str(x) for x in sorted(json_data['FaceDetails'][0]['AgeRange'].values()))
        # no way am I guessing a lady's age
        print "She looks young"
Amazon Rekognition responds with a JSON array with its findings:
     'FaceDetails': [{
         'Confidence': 99.99949645996094,
         'Gender': {
             'Confidence': 99.92884063720703,
             'Value': 'Male'
         'Emotions': [{
             'Confidence': 98.84156799316406,
             'Type': 'HAPPY'
         'AgeRange': {
             'High': 43,
             'Low': 26
         'Smile': {
             'Confidence': 98.52379608154297,
             'Value': True
         'Mustache': {
             'Confidence': 85.78340148925781,
             'Value': True
         'Beard': {
             'Confidence': 99.70159912109375,
             'Value': True
     }], 'OrientationCorrection': 'ROTATE_0'

The response contains an ever-growing list of features that Rekognition can detect, like emotions, age range and the presence of a smile, beard, mustache, etc. on a face.
For this example, I am parsing the JSON for the age range.
For the most part, the age range predicted is fairly accurate except in case of our VP of Finance Hunter Ferrell – he is much older than that. 🙂
That being said, here are our results:


Image of Franck
3 years ago

Gender recognition seems to have failed once 🙂

Image of Shiraz
3 years ago

Yeah I left that in there; I had asked him to take it up with AWS since I was only the messenger

Image of Sean
3 years ago

Age range was not terribly accurate for me! Of course, that’s not a great picture either!

Image of Dhiman Halder
Dhiman Halder
3 years ago

It’s a great AI service from Amazon – it brings deep learning to the masses, so impressed was I that I created an entire udemy course on the subject

Leave a Reply

Your email address will not be published. Required fields are marked *