per https://docs.aws.amazon.com/rekognition/latest/dg/labels-detect-labels-image.html#detectlabels-respons-response-respons-onsponse and https and https://docs。aws.amazon.com/rekognition/latest/dg/api_detectlabels.html,亚马逊rekognition应该返回实例(边界框详细信息)和每个标签的父母。但是,在成功运行具有类似于上述链接的实现的detect_labels时,我响应中的唯一键是"名称"one_answers"信心";"实例"one_answers"父母"甚至都不是钥匙,更不用说具有空的价值的钥匙了。
有人有任何想法吗?
我的代码如下:
def _bounding_box(imageFile):
client = boto3.client('rekognition')
with open(imageFile, 'rb') as image:
response = client.detect_labels(Image={'Bytes': image.read()})
print('Detected labels in ' + imageFile)
for label in response['Labels']:
print(label)
print("Label: " + label['Name'])
print("Confidence: " + str(label['Confidence']))
print("Instances:")
for instance in label['Instances']:
print(" Bounding box")
print(" Top: " + str(instance['BoundingBox']['Top']))
print(" Left: " + str(instance['BoundingBox']['Left']))
print(" Width: " + str(instance['BoundingBox']['Width']))
print(" Height: " + str(instance['BoundingBox']['Height']))
print(" Confidence: " + str(instance['Confidence']))
print()
print('Parents: ')
for parent in label['Parents']:
print(" " + parent['Name'])
print("----------")
print()
我能够准确地重现您的结果。
i然后更新了我的boto3
版本,并返回了Instances
信息。
-
Instances
未返回:版本1.9.16 -
Instances
返回:版本1.9.104
您可以发现以下版本:
>>> import boto3
>>> boto3.__version__
因此,更新您的boto3
。(pip install boto3 --upgrade
)
通常,使用虚拟环境使事物保持更干净是很好的。