Skip to content

Rekognize LabelInclusionFilters in API not working

0

As per this doc https://docs.aws.amazon.com/rekognition/latest/APIReference/API_DetectLabels.html I have a python 3.12 lamdba function running this code:

rekognition_client = boto3.client('rekognition', region_name=region)
try: response = rekognition_client.detect_labels( Image={'Bytes': image_bytes}, MaxLabels=100, # Adjust as needed for detailed results MinConfidence=70, Settings={ "GeneralLabels": { "LabelInclusionFilters": ["person"] } } )

It always return this error: (InvalidParameterException) when calling the DetectLabels operation: Request has invalid parameters.

If I remove the Settings part it works BUT I need to request specific label categories. I understand that limiting the categories in the request will improve performance and accuracy so want to use: LabelInclusionFilters and LabelCategoryInclusionFilters

So is the Boto3 documentation incorrect or I missed something??

asked 2 years ago122 views

2 Answers
0

Hello,

From my understanding, you are facing an InvalidParameterException with the DetectLabels API when providing the settings parameter.

The reason the InvalidParameterException is thrown is because the person label needs to be capitalized and exact based on the labels in reference [1]. After changing “person” to “Person”, this exception should be resolved. Please see full code snippet below.

response = rekognition_client.detect_labels(
    Image={'Bytes': image_bytes},
    MaxLabels=100, # Adjust as needed for detailed results
    MinConfidence=70,
    Settings={
        "GeneralLabels": {
            "LabelInclusionFilters": ["Person"]
        }
    }
)

Further answering your query, Settings filters out the returned items for both the GENERAL_LABELS and IMAGE_PROPERTIES features and does not improve performance and accuracy as this is a post response filter applied to the results.

If you have any difficulty or if you still run into issues, please reach out to AWS Support [2] (Rekognition) along with your issue or use case in detail, and we would be happy to assist you further.

Resources —

[1] https://docs.aws.amazon.com/rekognition/latest/dg/labels.html

[2] Creating support cases and case management: https://docs.aws.amazon.com/awssupport/latest/user/case-management.html#creating-a-support-casehttps://docs.aws.amazon.com/awssupport/latest/user/case-management.html#creating-a-support-case

AWS

answered 2 years ago

-1

The issue you're experiencing with the LabelInclusionFilters in the DetectLabels API call is likely due to a missing parameter in your request. The Settings parameter you're using is correct, but it needs to be accompanied by the Features parameter to specify which features you want to use.

To fix this, you should modify your code to include the Features parameter along with the Settings. Here's how you can update your code:

response = rekognition_client.detect_labels(
    Image={'Bytes': image_bytes},
    MaxLabels=100,
    MinConfidence=70,
    Features=["GENERAL_LABELS"],
    Settings={
        "GeneralLabels": {
            "LabelInclusionFilters": ["person"]
        }
    }
)

By adding the Features=["GENERAL_LABELS"] parameter, you're explicitly telling the API that you want to use the general labels feature, which is required when using the Settings parameter for label filtering.

The LabelInclusionFilters and LabelCategoryInclusionFilters are indeed designed to improve performance and accuracy by limiting the categories in the request. However, they need to be used in conjunction with the Features parameter to work correctly.

If you also want to include image properties in your response, you can add "IMAGE_PROPERTIES" to the Features list:

Features=["GENERAL_LABELS", "IMAGE_PROPERTIES"]

Remember that when using these filters, you need to provide the exact label names or label categories that you want to include. The "person" label you're using in your example should work, assuming it's a valid label in the Rekognition service.

If you continue to experience issues after making these changes, double-check that you're using the most recent version of the boto3 library, as there might have been updates to support these features.
Sources
DetectLabelsSettings - Amazon Rekognition
DetectLabels - Amazon Rekognition
Detecting labels in an image - Amazon Rekognition

answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.