简体   繁体   中英

Amazon Rekognition detect_labels does not return Instances or Parents

Per https://docs.aws.amazon.com/rekognition/latest/dg/labels-detect-labels-image.html#detectlabels-response and https://docs.aws.amazon.com/rekognition/latest/dg/API_DetectLabels.html , Amazon Rekognition should return Instances (bounding box details) and Parents with each label. However, upon successfully running detect_labels with an implementation similar to that of the above links, the only keys in my response are 'Name' and 'Confidence'; 'Instances' and 'Parents' are not even keys, let alone keys with empty values.

Does anyone have any thoughts?

My code is below:

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 was able to exactly reproduce your results.

I then updated my version of boto3 and the Instances information was returned.

  • Instances not returned: Version 1.9.16
  • Instances returned: Version 1.9.104

You can discover the version with:

>>> import boto3
>>> boto3.__version__

Therefore, update your boto3 . ( pip install boto3 --upgrade )

It is normally good to use virtual environments to keep things cleaner.

仅供参考,升级Boto对我没有帮助。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM