Amazon Rekognition using Python (boto3)

ANKIT JINDAL
4 min readJul 8, 2018

Not many Data Science enthusiasts who just graduated with a Master’s degree get to work on a ambitious business case in their first internship or job, which will eventually make an impact in an organisation. Luckily I got to work on a very exciting project which involved tagging player images with their features and Attributes (Name of Player/Players, No of Players in that Image, Emotions, labels etc.). I used Amazon Rekognition to train Images and Videos, which is super cool with lot of features to leverage. Here I am going to explain you step by step How you can leverage Amazon Rekognition in Python if you want to detect Images. Let’s get started,

First you need to create a AWS account (free for limited use), then in your IAM user profile (AWS authentication management) generate a key pair, save them in your local system. You will see a .aws folder. If you see one, you’r good to go, otherwise read the AWS documentation (it’s pretty good) for authentication and authorization. Copy your profile name in your .aws folder.

  1. Install boto3 in python using pip install boto3. (boto3 is a library, using which, you interact with AWS services in python)

2. Create a Session and Client for the AWS services (Rekognition in my case) that you want to use in Python.

3. Images are fed into Amazon Rekognition in the form of Image Bytes so first you need to convert them.

4. You can do a lot of things with Rekognition, we will explore some of it’s features like detecting objects and scenes, detecting celebrities in an Image etc. Let’s get started!

5. Just to get the feel of Image you are feeding to model, just plot it in python by doing something like this

6. Let’s plot a Image when want to analyze using Rekognition

Image that we will feed to the Amazon Rekognition

7. Call Recognize Celebrity function of Amazon Rekognition

8. Analyze the JSON Response

Here we can see the model has identified player as “Hiroshi Iwata” with 99.99 confidence. We all also capitalize all the face details, his Pose etc. Quite fun isn't it ;)

Now, We’ll take a look at Detect Faces feature of Amazon Rekognition.

8. Let’s plot another Image, This time Argubly India’s best captain ever in the game of Cricket Sourav Ganguly

Call Detect labels feature of Amazon Reko and add Attributes as [‘ALL’] (We can give minimum threshold for confidence here)

Analyze Response

We can see Model has identified most of the face features correctly, Age Range (35,52) is close, Eyeglasses Value is True with 99.9 % confidence, Beard and Mustache Value is False, Gender is Male, Eyes are Open, Face boundaries etc. We can analyze these features in a large set of Images by storing them in a Dataframe.

There are many more functions that one can leverage to detect n no of things in an Image. This can be really helpful in terms of Accuracy because Neural Networks that we model in our Jupyter Notebooks are really hard to scale up, also accuracy and Image Data is an Issue.

I will explain in the next article about, How you can train your own images in Amazon Rekognition, another powerful functionality to utilize for a specific business case.

--

--