没有错误:但它没有索引人脸,也没有生成人脸 ID

No errors: But its not indexing faces and not generating the face id's

非常感谢:)请找到完整的代码

导入 boto3

s3_client = boto3.client('s3', aws_access_key_id='xxxxxxxxxxxxx', aws_secret_access_key='xxxxxxxxxxxxxxxxx',)

collectionId='xxxxxxxxx' #集合名称

rek_client=boto3.client('rekognition', aws_access_key_id='xxxxxxxxxx', aws_secret_access_key='xxxxxxxxxxxxxxx',)

bucket = 'xxxxxxxxxxx' #S3 桶名

all_objects = s3_client.list_objects(桶=桶)

all_objects['Contents']中的内容:

collection_name, sep, collection_image =content['Key'].parition('/')

if collection_image:
    label = collection_name
    print('indexing: ',label)

    image = content['Key']
    index_response=rek_client.index_faces(CollectionId=collectionId,
                            Image={'S3Object': 'Bucket':bucket,'Name':image}},
                            ExternalImageId=label,
                            MaxFaces=1,
                            QualityFilter="AUTO", DetectionAttributes=['ALL'])

打印('FaceId: ',index_response['FaceRecords'][0]['Face']['FaceId'])

collection_name,collection_image =content['Key'].split('/')

要求 content['Key'] 包含 正好 一个正斜杠 (/)。

错误表明它包含 none,所以 .split('/') 只是返回相当于做 [content['Key']](用一个元素制作 list,整个内容content['Key'])。因此,您只有一个值要解包,但您尝试解包为两个值,并得到您看到的错误。

您要么需要过滤掉不符合您要求的值,要么使用一个系统来保证您获得预期数量的值,例如str.partition:

collection_name, sep, collection_image = content['Key'].partition('/')

使用str.partition,如果分区字符串没有出现,那么sepcollection_image会被赋值空字符串,"".