skip to Main Content

Below is a example of AWS Rekognition script to run object detection.
Was wondering if I can get some help on modifyin it.

import json
import boto3
def lambda_handler(event, context):
client = boto3.client("rekognition")
#passing s3 bucket object file reference    
response = client.detect_labels(Image = {"S3Object": {"Bucket":       "bucket_name", "Name": "image_name"}}, MaxLabels=3,  MinConfidence=70)
print(response)
return "Thanks"

Question 1: Here, it only reads a single image ("image_name") at a time. How can I run all images in the bucket?

Question 2: How can I save the response to json or csv file with same file name? for example, if apple.jpg, orange.jgp, and grape.jpg was used, I want each response to apple.json, orange.json, and grape.json.

Lastly, I heard that there is something like 50 image limit per day. Is this true?

Thank you,

2

Answers


  1. You have two choices:

    • Create a new Lambda where you can call the S3 ListObject API from boto3, iterate over all you images, call manually a second Lambda (similar to the one you posted in your question) and collect every response (or produce them directly from the second lambda, e.g. to a destination S3 bucket)
    • Orchestrate a Step Function that:
      • Call the first Lambda with the logic explained above
      • Map over the results, eventually using a Choice Node to filter if you need to
      • For every object mapped in the iteration, call the second Lambda
      • Collect or send somewhere else the outputs

    The first solution is probably more easy to achieve, but the second one permits to totally decouple the Lambdas and reuse them for future tasks.

    Regarding the last question: you can see every default or current quota on an account with the Service Quotas console.
    The only "50 limit" that I see on Rekognition is a 50 calls per second for the DetectCustomLabels API.

    Login or Signup to reply.
  2. A very similiar Python use case is located in the Official AWS Code Library.

    SDK for Python (Boto3)

    Shows you how to use the AWS SDK for Python (Boto3) to create a web application that lets you do the following:

    1. Upload photos to an Amazon Simple Storage Service (Amazon S3) bucket.

    2. Use Amazon Rekognition to analyze and label the photos. This covers how to send multiple objects to Amazon Rekognition.

    3. Use Amazon Simple Email Service (Amazon SES) to send email reports of image analysis. (THis put label data into a report. You can just as easily put Label data into JSON).

    Services used in this example

    1. Amazon Rekognition

    2. Amazon S3

    3. Amazon SES

    Analyze all photos in your S3 bucket and use Amazon SES to email a report.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search