Boto AWS Rekognition 错误
Error in Boto AWS Rekognition
我正尝试按照 AWS 文档中的说明使用 AWS Rekognitionthrough Python boto3 比较人脸。
我的 API 电话是:
client = boto3.client('rekognition', aws_access_key_id=key, aws_secret_access_key=secret, region_name=region )
source_bytes = open('source.jpg', 'rb')
target_bytes = open('target.jpg', 'rb')
response = client.compare_faces(
SourceImage = {
'Bytes':bytearray(source_bytes.read())
},
TargetImage = {
'Bytes':bytearray(target_bytes.read())
},
SimilarityThreshold = SIMILARITY_THRESHOLD
)
source_image.close()
target_image.close()
但是每次我 运行 这个程序,我都会得到以下错误:
botocore.errorfactory.InvalidParameterException: An error occurred (InvalidParameterException) when calling the CompareFaces operation: Request has Invalid Parameters
我已经正确指定了密钥、密钥、区域和阈值。如何清除此错误并使请求调用正常工作?
您的代码非常好,
对于 AWS Rekognition,图像尺寸很重要。
Amazon Rekognition 中的限制
以下是 Amazon Rekognition 中的限制列表:
- 存储为 Amazon S3 对象的最大图像大小限制为 15 MB。
- 高度和宽度的最小像素分辨率为 80 pixels.Maximum 作为参数传入 API 的原始字节图像大小为 5 MB。
- Amazon Rekognition 支持 PNG 和 JPEG 图像格式。也就是说,您作为各种 API 操作(例如 DetectLabels 和 IndexFaces)的输入提供的图像必须采用受支持的格式之一。
- 单个人脸集合中最多可存储 100 万张人脸。
最大匹配面搜索APIreturns为4096。
来源:AWS Docs
您打开文件的方式,不需要强制转换为 bytearray。
试试这个:
client = boto3.client('rekognition', aws_access_key_id=key, aws_secret_access_key=secret, region_name=region )
source_bytes = open('source.jpg', 'rb')
target_bytes = open('target.jpg', 'rb')
response = client.compare_faces(
SourceImage = {
'Bytes':source_bytes.read()
},
TargetImage = {
'Bytes':target_bytes.read()
},
SimilarityThreshold = SIMILARITY_THRESHOLD
)
source_image.close()
target_image.close()
对于那些仍在寻找答案的人,
我遇到了同样的问题,而@mohanbabu 指出了官方文档中应该包含 compare_faces
的内容,我意识到 compare_faces
在两个 [=12= 中寻找面孔] 和 TargetImage
。我通过首先使用 aws 的 detect_faces
检测人脸并将检测到的人脸传递给 compare_faces
来确认这一点。
compare_faces
几乎总是在 detect_faces
检测到的人脸有点模糊时失败。
所以,如果你的 SourceImage
或 TargetImage
中的任何一个被紧紧地裁剪到脸 AND
那张脸不是很明显,compare_faces
就会失败。
可能还有其他原因,但这个观察对我有用。
例如:
在上图中你可以相当自信地说中间有一张脸
但是,
现在,不那么明显了。
这至少是我的原因,检查你的图片你应该知道。
我正尝试按照 AWS 文档中的说明使用 AWS Rekognitionthrough Python boto3 比较人脸。
我的 API 电话是:
client = boto3.client('rekognition', aws_access_key_id=key, aws_secret_access_key=secret, region_name=region )
source_bytes = open('source.jpg', 'rb')
target_bytes = open('target.jpg', 'rb')
response = client.compare_faces(
SourceImage = {
'Bytes':bytearray(source_bytes.read())
},
TargetImage = {
'Bytes':bytearray(target_bytes.read())
},
SimilarityThreshold = SIMILARITY_THRESHOLD
)
source_image.close()
target_image.close()
但是每次我 运行 这个程序,我都会得到以下错误:
botocore.errorfactory.InvalidParameterException: An error occurred (InvalidParameterException) when calling the CompareFaces operation: Request has Invalid Parameters
我已经正确指定了密钥、密钥、区域和阈值。如何清除此错误并使请求调用正常工作?
您的代码非常好,
对于 AWS Rekognition,图像尺寸很重要。
Amazon Rekognition 中的限制
以下是 Amazon Rekognition 中的限制列表:
- 存储为 Amazon S3 对象的最大图像大小限制为 15 MB。
- 高度和宽度的最小像素分辨率为 80 pixels.Maximum 作为参数传入 API 的原始字节图像大小为 5 MB。
- Amazon Rekognition 支持 PNG 和 JPEG 图像格式。也就是说,您作为各种 API 操作(例如 DetectLabels 和 IndexFaces)的输入提供的图像必须采用受支持的格式之一。
- 单个人脸集合中最多可存储 100 万张人脸。 最大匹配面搜索APIreturns为4096。
来源:AWS Docs
您打开文件的方式,不需要强制转换为 bytearray。
试试这个:
client = boto3.client('rekognition', aws_access_key_id=key, aws_secret_access_key=secret, region_name=region )
source_bytes = open('source.jpg', 'rb')
target_bytes = open('target.jpg', 'rb')
response = client.compare_faces(
SourceImage = {
'Bytes':source_bytes.read()
},
TargetImage = {
'Bytes':target_bytes.read()
},
SimilarityThreshold = SIMILARITY_THRESHOLD
)
source_image.close()
target_image.close()
对于那些仍在寻找答案的人,
我遇到了同样的问题,而@mohanbabu 指出了官方文档中应该包含 compare_faces
的内容,我意识到 compare_faces
在两个 [=12= 中寻找面孔] 和 TargetImage
。我通过首先使用 aws 的 detect_faces
检测人脸并将检测到的人脸传递给 compare_faces
来确认这一点。
compare_faces
几乎总是在 detect_faces
检测到的人脸有点模糊时失败。
所以,如果你的 SourceImage
或 TargetImage
中的任何一个被紧紧地裁剪到脸 AND
那张脸不是很明显,compare_faces
就会失败。
可能还有其他原因,但这个观察对我有用。
例如:
在上图中你可以相当自信地说中间有一张脸
但是,
现在,不那么明显了。
这至少是我的原因,检查你的图片你应该知道。