Exploring the benefits of Amazon Rekognition – AWS Application Services for AI/ML – MLS-C01 Study Guide
Exploring the benefits of Amazon Rekognition
Here are some of the benefits of using Amazon Rekognition:
AWS manages the infrastructure it runs on. In short, just use the API for your image analysis. You need to only focus on building and managing your deep learning pipelines.
With or without knowledge of image processing, you can perform image and video analysis just by using the APIs provided in Amazon Rekognition, which can be used for any application or service on several platforms.
The Labels API’s response will identify real-world entities within an image through the DetectLabels API. These labels include city, town, table, home, garden, animal, pets, food, drink, electronics, flowers, and more. The entities are classified based on their confidence score, which indicates the probability that a given prediction is correct — the higher the score, the better. Similarly, you can use the DetectText API to extract the text in an image. Amazon Rekognition may detect multiple lines based on the gap between words. Periods do not represent the end of a line.
Amazon Rekognition can be integrated with AWS Kinesis Video Stream, AWS S3, and AWS Lambda for seamless and affordable image and video analysis. With the AWS IAM service, Amazon Rekognition API calls can easily be secured and controlled.
Low cost: you only pay for the images and videos that are analyzed.
Through AWS CloudTrail, all the API calls for Amazon Rekognition can be captured as events. It captures all calls made from the console, the CLI, or code calls for APIs, which further enables the user to create Amazon SNS notifications based on CloudTrail events.
You can create a VPC endpoint policy for specific API calls to establish a private connection between your VPC and Amazon Rekognition. This helps you leverage enhanced security. As per the AWS Shared Responsibility Model, AWS takes care of the security of the infrastructure and software, and you have to take care of the security of your content in the cloud.
Getting hands-on with Amazon Rekognition
In this section, you will learn how to integrate AWS Lambda with Amazon Rekognition to detect the labels in our image (uploaded at https://github.com/PacktPublishing/AWS-Certified-Machine-Learning-Specialty-MLS-C01-Certification-Guide-Second-Edition/tree/main/Chapter08/Amazon%20Rekognition%20Demo/images) and print the detected objects in the CloudWatch console. You will use the detect_labels API from Amazon Rekognition in the code.
You will begin by creating an IAM role for Lambda:
Navigate to the IAM console page.
Select Roles from the left-hand menu.
Select Create role.
Select Lambda from the Choose a use case section.
Add the following managed policies:
AmazonS3ReadOnlyAccess
AmazonRekognitionFullAccess
CloudWatchLogsFullAccess
Name the role rekognition-lambda-role:
Figure 8.1 – The Create role dialog
Next, you will create a Lambda function.
Navigate to the AWS Lambda console page.
Select Create function.
Create a function:
Select Author from scratch.
Select Use an existing role. Add the name of the role you created previously; that is, rekognition-lambda-role:
Give the function a name, such as lambda-rekognition.Choose Python 3.6 from the Runtime dropdown.
Now, you will create a trigger for the Lambda Function.
Navigate to the AWS S3 console page. Create a bucket, for example, rekognition-test-baba, as shown in Figure 8.3:
Figure 8.3 – AWS S3 console page
Click on Create folder and name it images. Click Save.
Click the Properties tab of our bucket.
Scroll to Events for that bucket.
Inside the Events window, select Add notification and set the following properties:
Name: rekognition_event
Events: All object create events
Prefix: images
/Send to: Lambda Function
Lambda: lambda-rekognition:
Figure 8.4 – S3 bucket Events window
Next, you will upload the image from the shared GitHub repository to the S3 bucket images folder.
As soon as you upload, you can check the Monitoring tab in the Lambda console to monitor the events, as shown in Figure 8.5:
Figure 8.5 – CloudWatch monitoring the event in the Lambda console
Navigate to CloudWatch > CloudWatch Logs > Log groups > /aws/lambda/lambda-rekognition. Select the latest stream from all the streams listed on the AWS console and scroll down in the logs to see your output.
In this section, you learned how to implement the Amazon Rekognition AI service to detect objects in an image and get a confidence score for each. You will see more use cases for Amazon Rekognition in the upcoming sections, where you will detect text in images. In the next section, you will learn about Amazon’s text-to-speech service and implement it.