Rekognition - Invalid ParameterException problem

0

Greetings, I've set up a successfully run a python script that will take a source image and do facial comparision against an S3 image sub-directory. However, when I add a .png which does not have any faces in it, I get this error:

Error comparing source/isla.JPG and fred/safewatch.png: An error occurred (InvalidParameterException) when calling the CompareFaces operation: Request has invalid parameters

I do have other .jpg images that don't have faces in them and my code is set to print, 'nope, no match in' image name. Which does work nicely. Like the isla.JPG above compared to a .jpg image of a tent with no people. It works, no problem. My question is: When rekognition throws up the error I mention, is there a way to get more detailed information as to why that particular image isn't liked. Any thoughts gratefully appreciated.

Rick

profile picture
질문됨 3달 전168회 조회
1개 답변
3
수락된 답변

Hi THere

That error usually means no face was detected.

From the documentation: If no faces are detected in the source or target images, CompareFaces returns an InvalidParameterException error.

Make sure you are handling errors in your code properly. Heres an example. Its using DetectLabels, but the error handling would be similar for CompareFaces

import boto3

rekognition = boto3.client('rekognition')

try:
    response = rekognition.detect_labels(Image={'S3Object': {'Bucket': bucket, 'Name': photo}})
    labels = response['Labels']
    
    print(f"Detected labels for {photo}")
    for label in labels:
        print(f"{label['Name']}: {label['Confidence']}")
        
except rekognition.exceptions.AmazonRekognitionException as e:
    print("Could not complete operation")
    print(f"Error Message: {e.message}")
    print(f"HTTP Status: {e.response['Error']['Code']}")
    print(f"AWS Error Code: {e.response['Error']['Code']}")
    print(f"Error Type: {e.response['Error']['Type']}")
    print(f"Request ID: {e.response['ResponseMetadata']['RequestId']}")

except Exception as e:
    print(f"Internal error occurred communicating with Rekognition: {e}")
profile pictureAWS
전문가
Matt-B
답변함 3달 전
profile picture
전문가
검토됨 2달 전
profile pictureAWS
전문가
검토됨 3달 전
  • Thanks, Matt. I'm not sure why the error isn't consistent with each photo that doesn't have a face in it. I get 'nope' on most and on this one image I get this error. I can trap for it, for sure but just wish I knew more as to why. Thanks for the quick response.

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠