gpt4 book ai didi

python - 没有错误 : But its not indexing faces and not generating the face id's

转载 作者:太空宇宙 更新时间:2023-11-03 20:28:13 26 4
gpt4 key购买 nike

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

导入boto3

s3_client = boto3.client('s3', aws_access_key_id='xxxxxxxxxxxxxxx', aws_secret_access_key='xxxxxxxxxxxxxxxx',)

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(Bucket =bucket)

对于 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'])

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

最佳答案

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

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

该错误表明它不包含任何内容,因此 .split('/') 只是返回了与执行 [content['Key']] 等效的操作(制作list 包含一个元素,即 content['Key'] 的全部内容)。因此,您只有一个值需要解包,但您尝试解包为两个值,并得到了您看到的错误。

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

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

使用str.partition,如果分区字符串没有出现,那么sepcollection_image将被分配空字符串,“”

关于python - 没有错误 : But its not indexing faces and not generating the face id's,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57678172/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com