Get startedGet started for free

Rekognizing patterns

1. Rekognizing patterns

As we jump into the last chapter of the course, I want to emphasize we did not only learn S3, SNS, and Boto3 in the past chapters. We learned a pattern that we can apply to AWS services I didn't teach and services that don't exist yet.

2. Rekognition

Boto3 follows the same pattern for all AWS services. As new services come online, we will be able to interact with them using familiar patterns. We will be using Boto3 documentation and the AWS interface to explore a new service called Rekognition. Get the super witty Rekognizing patterns title? Let's get started.

3. So what is Rekognition anyway?

Rekognition is computer vision API by AWS. We will focus on 2 features: Detecting objects in an image and Extracting text from images. These are common tasks extremely useful in day to day operations. But if we dig around in the docs, Rekognition does a few other things.

4. Why not build our own?

You may wonder why we should use Rekognition instead of building our own model. If we were building our own, we would train it for one specific task - like recognizing bicycles. We have to have training data, deploy the model and maintain it. But, a good data engineer is a lazy data engineer. Rekognition is a great general-purpose model, and we should stick with it if we want simplicity. We can always go custom if we need more customization.

5. I am not a computer vision expert

I should also note - I'm not a computer vision expert. But to use Rekognition and boto, I don't have to be.

6. Learning a new AWS service

When I learned how to use Rekognition, I clicked around on the AWS interface.

7. Learning a new AWS service

Then I looked up Rekognition in Available Services in Boto Docs.

8. Learning a new AWS service

I found the parameter to pass to create the client.

9. Learning a new AWS service

Then I was able to see the available operations. Let's explore them!

10. Upload an image to S3

Let's see how we can use rekognition for object detection. The City wants to count bicycles as they pass by a camera. Before we do anything, we must upload an image to S3. As a reminder, we initialize the S3 client, then call the upload_file method.

11. Object detection

Then, construct the boto3 rekognition client.

12. Object detection

Call detect_labels, specifying Bucket and Image to get the response from Rekognition. Optionally, we can specify the maximum amount of labels to return and the minimum confidence in the match that we are willing to accept.

13. Detect labels response

The response will come back as a list of labels. This label Name is Bicycle.

14. Detect labels response

We are 99% Confident that there is a Bicycle in this image.

15. Detect labels response

The list of label instances contains information about all the instances of the Bicycle label in the image.

16. Detect labels response

There is a list item for every label.

17. Detect labels response

In this image, Rekognition sees 1 bicycle and many cars.

18. Text detection

Text detection works in a similar way. We instantiate the client, then call detect_text, passing an image bucket and key.

19. Text detection response

We receive a response containing text detections as a list of dictionaries. Detections can be of 2 types: Line or Word. A line detection treats the text in the adjacent signs as one line. One of the detections was "STREET PROHIBITED", a combination of one line across 2 signs.

20. Text detection response

But word detections simply separate by word.

21. What Rekognition sees

The response contains ALL line and word detections.

22. Summary

In this lesson, we learned how to detect objects in an image and count instances of them. We talked about how to approach learning a new AWS service with Boto. We looked at how to recognize text in an image and tell the difference between word and line detection. We also explored when to build our own or use a service like Rekognition.

23. Let's do some computer vision!

But we'll only learn so much in slides. Let's continue helping Sam!