Example of Celebrity Rekognition with AWS

[This article was first published on Python – Predictive Hacks, and kindly contributed to python-bloggers]. (You can report issue about the content on this page here)
Want to share your content on python-bloggers? click here.

Rekognition with Console

Amazon Rekognition gives us the chance to recognize celebrities in images and videos. For our example, I will choose the images of Antentokounmpo Brothers and we will see if the Rekognition can recognize them.

Giannis Antetokounmpo Brothers: All You Need To Know – SportyTell
Image Address

You can try this image in the AWS Console. Let’s see what we get:

Example of Celebrity Rekognition with AWS 1

As we can see, it managed to detect Giannis and Thanasis Antentokounmpo! The rest brothers should wait until they become true celebrities apparently 🙂

Rekognition with boto3

We can get call the API via Python and boto3 and we can get all the info from the API response which is in json format. We will provide an example of how you can simply get the name of the celebrities. We will work again with the same image.

import boto3
import json

# create a connection with the rekognition

#define the photo
photo = "Giannis-Antetokounmpo-Brothers.jpg"

# call the API and get the response
with open(photo, 'rb') as image:
    response = client.recognize_celebrities(Image={'Bytes': image.read()})
for celebrity in response['CelebrityFaces']:
    print ('Name: ' + celebrity['Name'] + ' with Confidence: ' + str(celebrity['MatchConfidence']))


Name: Thanasis Antetokounmpo with Confidence: 58.999996185302734
Name: Giannis Antetokounmpo with Confidence: 57.0

Notice that the response contains much information like the Bounding Boxes etc.

As you can see we used the boto3, if you want to learn more about it you can have a look at the Basic Introduction to Boto3

To leave a comment for the author, please follow the link and comment on their blog: Python – Predictive Hacks.

Want to share your content on python-bloggers? click here.