问题描述
从下面我从AWS Rekognition(boto3 = python)使用的脚本开始:
pics = [f'LP {num}.jpg' for num in range(1,5)]
for pic in pics :
request = {
'S3Object': {
'Bucket': 'test1','Name': pic
}
}
response = client.detect_labels(Image=request)
json_file = json.dumps(response)
Path(f"{pic}.json").write_text(json_file)
我正在尝试运行名为LP 1,LP 2,LP 3和LP 4的4张图像,然后将每个响应保存到单独的JSON文件中。
问题1:我不确定为什么,但是我的脚本仅保存一个响应文件,而不是所有4张图像。例如,如果将范围设置为(1,5),则仅保存LP 4的响应。如果将范围设置为(1,4),则仅保存LP 3的响应。
问题2:我正在尝试使用以下脚本将响应保存为特定格式,但效果不佳:
print(f"{label['Name']} - {label['Confidence']}")
谢谢!
解决方法
pics = [f'LP {num}.jpg' for num in range(1,5)]
for pic in pics :
request = {
'S3Object': {
'Bucket': 'test1','Name': pic
}
}
response = client.detect_labels(Image=request)
json_file = json.dumps(response)
# what is the value of Key? - change it during the loop
Path(f"{Key}.json").write_text(json_file)