The below code is for AWS Rekognition image label detection.
Question 1) Since AWS Recognition can only run one image at a time, I used [List] to add multiple images at a time. However, what if I want to run 100 images? this means I have to manually write name for 100 images in that [List] which will take forever. What is the best way to solve this issue supposing I have 100 images named image1, image2, image3, ... image100?
Question 2) The below code will save the response for all 3 images to a single JSON file. How can the response be saved into an individual file?
# List to record all the responses
responselist=[]
list=['picture1.jpg','picture2.jpg','picture 3.jpg']
for image in list :
response = client.detect_labels(
Image={
'S3Object': {
'Bucket': 'test1',
'Name': image
}})
responselist.append(response)
print(response)
# JASON file Save
json_file = json.dumps(response)
Path('rekognition_test.json').write_text(json_file)
list_objectswith certain extensions like*.jpgand with regards to save to json you can use the image name to add json extension to it. - error404