Contact Us

Content moderation with AWS Rekognition


By abdulmumin yaqeen

on June 16, 2023



img

Content moderation with AWS Rekognition

Introduction

AWS Rekognition provides a cloud-based pre-trained AI model that uses deep learning to analyze and extract information from images, videos, and text.

With Rekognition API, it becomes much easier to build a solution that moderates content in your platforms. It offers a ready-to-use and a wide range of computer vision capabilities, including object detection, text detection, image comparison, and much more.

Rekognition also becomes handy when building an automated identity verification system, with its image comparison API, it extracts features from images and matches them against another.

Image Sampling Demo

Rekognition provides a variety of APIs that analyze images. From detecting faces, objects, and text to comparing them against one another.

Using the DetectModerationLabels API from Rekognition, we will write a lambda function that reads an image from an S3 bucket and returns details about the image. This information includes inappropriate objects in the image, bounding boxes of where each is located, and others.

We will be setting up a simple image moderation function using lambda. Almost the same approach goes for videos, but it will require you to go through all frames in the video, store and sample them one after another.

Create a lambda function.

Login to your AWS console and create a new lambda function. No additional setting is required in setting up your lambda function, except that we will be using Python as the running environment for this demo.

image1

Attach Policies

Our Lambda function will need permission to use both S3 and Rekognition.

We will attach the following policies to our function:

NOTE: If you need more than Read Only Access, you can instead attach the Full Access.

Go to the Configurations tab > Permissions in your lambda function.

image2

Click the link in the Execution role to open up the IAM Console of this function.

image3

Click Attach Policies.

Search s3 and press Enter, then select the AmazonS3ReadOnlyAccess.

image4

Clear filters and search rekognition and press Enter, then select the AmazonRekognitionReadOnlyAccess.

image5

Click Add Permissions, and you can review the attached policies.

image6

Create Bucket

Create a bucket and upload some demo images.

image7

Code Walkthrough

Back to the function.

image8

Example of response

image9

In the lambda_handler function, we specify the name of the image and bucket and then call the moderate_image function.

Testing

To Test the Function, create a new Test with an hello-world test.