Amazon Rekognition

2021/11/01 - Amazon Rekognition - 7 new 1 updated api methods

Changes  This Amazon Rekognition Custom Labels release introduces the management of datasets with projects

DescribeDataset (new) Link ¶

Describes an Amazon Rekognition Custom Labels dataset. You can get information such as the current status of a dataset and statistics about the images and labels in a dataset.

This operation requires permissions to perform the rekognition:DescribeDataset action.

See also: AWS API Documentation

Request Syntax

client.describe_dataset(
    DatasetArn='string'
)
type DatasetArn

string

param DatasetArn

[REQUIRED]

The Amazon Resource Name (ARN) of the dataset that you want to describe.

rtype

dict

returns

Response Syntax

{
    'DatasetDescription': {
        'CreationTimestamp': datetime(2015, 1, 1),
        'LastUpdatedTimestamp': datetime(2015, 1, 1),
        'Status': 'CREATE_IN_PROGRESS'|'CREATE_COMPLETE'|'CREATE_FAILED'|'UPDATE_IN_PROGRESS'|'UPDATE_COMPLETE'|'UPDATE_FAILED'|'DELETE_IN_PROGRESS',
        'StatusMessage': 'string',
        'StatusMessageCode': 'SUCCESS'|'SERVICE_ERROR'|'CLIENT_ERROR',
        'DatasetStats': {
            'LabeledEntries': 123,
            'TotalEntries': 123,
            'TotalLabels': 123,
            'ErrorEntries': 123
        }
    }
}

Response Structure

  • (dict) --

    • DatasetDescription (dict) --

      The description for the dataset.

      • CreationTimestamp (datetime) --

        The Unix timestamp for the time and date that the dataset was created.

      • LastUpdatedTimestamp (datetime) --

        The Unix timestamp for the date and time that the dataset was last updated.

      • Status (string) --

        The status of the dataset.

      • StatusMessage (string) --

        The status message for the dataset.

      • StatusMessageCode (string) --

        The status message code for the dataset operation. If a service error occurs, try the API call again later. If a client error occurs, check the input parameters to the dataset API call that failed.

      • DatasetStats (dict) --

        The status message code for the dataset.

        • LabeledEntries (integer) --

          The total number of images in the dataset that have labels.

        • TotalEntries (integer) --

          The total number of images in the dataset.

        • TotalLabels (integer) --

          The total number of labels declared in the dataset.

        • ErrorEntries (integer) --

          The total number of entries that contain at least one error.

ListDatasetEntries (new) Link ¶

Lists the entries (images) within a dataset. An entry is a JSON Line that contains the information for a single image, including the image location, assigned labels, and object location bounding boxes. For more information, see Creating a manifest file.

JSON Lines in the response include information about non-terminal errors found in the dataset. Non terminal errors are reported in errors lists within each JSON Line. The same information is reported in the training and testing validation result manifests that Amazon Rekognition Custom Labels creates during model training.

You can filter the response in variety of ways, such as choosing which labels to return and returning JSON Lines created after a specific date.

This operation requires permissions to perform the rekognition:ListDatasetEntries action.

See also: AWS API Documentation

Request Syntax

client.list_dataset_entries(
    DatasetArn='string',
    ContainsLabels=[
        'string',
    ],
    Labeled=True|False,
    SourceRefContains='string',
    HasErrors=True|False,
    NextToken='string',
    MaxResults=123
)
type DatasetArn

string

param DatasetArn

[REQUIRED]

The Amazon Resource Name (ARN) for the dataset that you want to use.

type ContainsLabels

list

param ContainsLabels

Specifies a label filter for the response. The response includes an entry only if one or more of the labels in ContainsLabels exist in the entry.

  • (string) --

type Labeled

boolean

param Labeled

Specify true to get only the JSON Lines where the image is labeled. Specify false to get only the JSON Lines where the image isn't labeled. If you don't specify Labeled , ListDatasetEntries returns JSON Lines for labeled and unlabeled images.

type SourceRefContains

string

param SourceRefContains

If specified, ListDatasetEntries only returns JSON Lines where the value of SourceRefContains is part of the source-ref field. The source-ref field contains the Amazon S3 location of the image. You can use SouceRefContains for tasks such as getting the JSON Line for a single image, or gettting JSON Lines for all images within a specific folder.

type HasErrors

boolean

param HasErrors

Specifies an error filter for the response. Specify True to only include entries that have errors.

type NextToken

string

param NextToken

If the previous response was incomplete (because there is more results to retrieve), Amazon Rekognition Custom Labels returns a pagination token in the response. You can use this pagination token to retrieve the next set of results.

type MaxResults

integer

param MaxResults

The maximum number of results to return per paginated call. The largest value you can specify is 100. If you specify a value greater than 100, a ValidationException error occurs. The default value is 100.

rtype

dict

returns

Response Syntax

{
    'DatasetEntries': [
        'string',
    ],
    'NextToken': 'string'
}

Response Structure

  • (dict) --

    • DatasetEntries (list) --

      A list of entries (images) in the dataset.

      • (string) --

    • NextToken (string) --

      If the previous response was incomplete (because there is more results to retrieve), Amazon Rekognition Custom Labels returns a pagination token in the response. You can use this pagination token to retrieve the next set of results.

DeleteDataset (new) Link ¶

Deletes an existing Amazon Rekognition Custom Labels dataset. Deleting a dataset might take while. Use DescribeDataset to check the current status. The dataset is still deleting if the value of Status is DELETE_IN_PROGRESS . If you try to access the dataset after it is deleted, you get a ResourceNotFoundException exception.

You can't delete a dataset while it is creating ( Status = CREATE_IN_PROGRESS ) or if the dataset is updating ( Status = UPDATE_IN_PROGRESS ).

This operation requires permissions to perform the rekognition:DeleteDataset action.

See also: AWS API Documentation

Request Syntax

client.delete_dataset(
    DatasetArn='string'
)
type DatasetArn

string

param DatasetArn

[REQUIRED]

The ARN of the Amazon Rekognition Custom Labels dataset that you want to delete.

rtype

dict

returns

Response Syntax

{}

Response Structure

  • (dict) --

UpdateDatasetEntries (new) Link ¶

Adds or updates one or more entries (images) in a dataset. An entry is a JSON Line which contains the information for a single image, including the image location, assigned labels, and object location bounding boxes. For more information, see Image-Level labels in manifest files and Object localization in manifest files in the Amazon Rekognition Custom Labels Developer Guide .

If the source-ref field in the JSON line references an existing image, the existing image in the dataset is updated. If source-ref field doesn't reference an existing image, the image is added as a new image to the dataset.

You specify the changes that you want to make in the Changes input parameter. There isn't a limit to the number JSON Lines that you can change, but the size of Changes must be less than 5MB.

UpdateDatasetEntries returns immediatly, but the dataset update might take a while to complete. Use DescribeDataset to check the current status. The dataset updated successfully if the value of Status is UPDATE_COMPLETE .

To check if any non-terminal errors occured, call ListDatasetEntries and check for the presence of errors lists in the JSON Lines.

Dataset update fails if a terminal error occurs ( Status = UPDATE_FAILED ). Currently, you can't access the terminal error information from the Amazon Rekognition Custom Labels SDK.

This operation requires permissions to perform the rekognition:UpdateDatasetEntries action.

See also: AWS API Documentation

Request Syntax

client.update_dataset_entries(
    DatasetArn='string',
    Changes={
        'GroundTruth': b'bytes'
    }
)
type DatasetArn

string

param DatasetArn

[REQUIRED]

The Amazon Resource Name (ARN) of the dataset that you want to update.

type Changes

dict

param Changes

[REQUIRED]

The changes that you want to make to the dataset.

  • GroundTruth (bytes) -- [REQUIRED]

    A Base64-encoded binary data object containing one or JSON lines that either update the dataset or are additions to the dataset. You change a dataset by calling UpdateDatasetEntries. If you are using an AWS SDK to call UpdateDatasetEntries , you don't need to encode Changes as the SDK encodes the data for you.

    For example JSON lines, see Image-Level labels in manifest files and and Object localization in manifest files in the Amazon Rekognition Custom Labels Developer Guide .

rtype

dict

returns

Response Syntax

{}

Response Structure

  • (dict) --

DistributeDatasetEntries (new) Link ¶

Distributes the entries (images) in a training dataset across the training dataset and the test dataset for a project. DistributeDatasetEntries moves 20% of the training dataset images to the test dataset. An entry is a JSON Line that describes an image.

You supply the Amazon Resource Names (ARN) of a project's training dataset and test dataset. The training dataset must contain the images that you want to split. The test dataset must be empty. The datasets must belong to the same project. To create training and test datasets for a project, call CreateDataset.

Distributing a dataset takes a while to complete. To check the status call DescribeDataset . The operation is complete when the Status field for the training dataset and the test dataset is UPDATE_COMPLETE . If the dataset split fails, the value of Status is UPDATE_FAILED .

This operation requires permissions to perform the rekognition:DistributeDatasetEntries action.

See also: AWS API Documentation

Request Syntax

client.distribute_dataset_entries(
    Datasets=[
        {
            'Arn': 'string'
        },
    ]
)
type Datasets

list

param Datasets

[REQUIRED]

The ARNS for the training dataset and test dataset that you want to use. The datasets must belong to the same project. The test dataset must be empty.

  • (dict) --

    A training dataset or a test dataset used in a dataset distribution operation. For more information, see DistributeDatasetEntries.

    • Arn (string) -- [REQUIRED]

      The Amazon Resource Name (ARN) of the dataset that you want to use.

rtype

dict

returns

Response Syntax

{}

Response Structure

  • (dict) --

ListDatasetLabels (new) Link ¶

Lists the labels in a dataset. Amazon Rekognition Custom Labels uses labels to describe images. For more information, see Labeling images.

Lists the labels in a dataset. Amazon Rekognition Custom Labels uses labels to describe images. For more information, see Labeling images in the Amazon Rekognition Custom Labels Developer Guide .

See also: AWS API Documentation

Request Syntax

client.list_dataset_labels(
    DatasetArn='string',
    NextToken='string',
    MaxResults=123
)
type DatasetArn

string

param DatasetArn

[REQUIRED]

The Amazon Resource Name (ARN) of the dataset that you want to use.

type NextToken

string

param NextToken

If the previous response was incomplete (because there is more results to retrieve), Amazon Rekognition Custom Labels returns a pagination token in the response. You can use this pagination token to retrieve the next set of results.

type MaxResults

integer

param MaxResults

The maximum number of results to return per paginated call. The largest value you can specify is 100. If you specify a value greater than 100, a ValidationException error occurs. The default value is 100.

rtype

dict

returns

Response Syntax

{
    'DatasetLabelDescriptions': [
        {
            'LabelName': 'string',
            'LabelStats': {
                'EntryCount': 123,
                'BoundingBoxCount': 123
            }
        },
    ],
    'NextToken': 'string'
}

Response Structure

  • (dict) --

    • DatasetLabelDescriptions (list) --

      A list of the labels in the dataset.

      • (dict) --

        Describes a dataset label. For more information, see ListDatasetLabels.

        • LabelName (string) --

          The name of the label.

        • LabelStats (dict) --

          Statistics about the label.

          • EntryCount (integer) --

            The total number of images that use the label.

          • BoundingBoxCount (integer) --

            The total number of images that have the label assigned to a bounding box.

    • NextToken (string) --

      If the previous response was incomplete (because there is more results to retrieve), Amazon Rekognition Custom Labels returns a pagination token in the response. You can use this pagination token to retrieve the next set of results.

CreateDataset (new) Link ¶

Creates a new Amazon Rekognition Custom Labels dataset. You can create a dataset by using an Amazon Sagemaker format manifest file or by copying an existing Amazon Rekognition Custom Labels dataset.

To create a training dataset for a project, specify train for the value of DatasetType . To create the test dataset for a project, specify test for the value of DatasetType .

The response from CreateDataset is the Amazon Resource Name (ARN) for the dataset. Creating a dataset takes a while to complete. Use DescribeDataset to check the current status. The dataset created successfully if the value of Status is CREATE_COMPLETE .

To check if any non-terminal errors occurred, call ListDatasetEntries and check for the presence of errors lists in the JSON Lines.

Dataset creation fails if a terminal error occurs ( Status = CREATE_FAILED ). Currently, you can't access the terminal error information.

For more information, see Creating dataset in the Amazon Rekognition Custom Labels Developer Guide .

This operation requires permissions to perform the rekognition:CreateDataset action. If you want to copy an existing dataset, you also require permission to perform the rekognition:ListDatasetEntries action.

See also: AWS API Documentation

Request Syntax

client.create_dataset(
    DatasetSource={
        'GroundTruthManifest': {
            'S3Object': {
                'Bucket': 'string',
                'Name': 'string',
                'Version': 'string'
            }
        },
        'DatasetArn': 'string'
    },
    DatasetType='TRAIN'|'TEST',
    ProjectArn='string'
)
type DatasetSource

dict

param DatasetSource

The source files for the dataset. You can specify the ARN of an existing dataset or specify the Amazon S3 bucket location of an Amazon Sagemaker format manifest file. If you don't specify datasetSource , an empty dataset is created. To add labeled images to the dataset, You can use the console or call UpdateDatasetEntries.

  • GroundTruthManifest (dict) --

    The S3 bucket that contains an Amazon Sagemaker Ground Truth format manifest file.

    • S3Object (dict) --

      Provides the S3 bucket name and object name.

      The region for the S3 bucket containing the S3 object must match the region you use for Amazon Rekognition operations.

      For Amazon Rekognition to process an S3 object, the user must have permission to access the S3 object. For more information, see Resource-Based Policies in the Amazon Rekognition Developer Guide.

      • Bucket (string) --

        Name of the S3 bucket.

      • Name (string) --

        S3 object key name.

      • Version (string) --

        If the bucket is versioning enabled, you can specify the object version.

  • DatasetArn (string) --

    The ARN of an Amazon Rekognition Custom Labels dataset that you want to copy.

type DatasetType

string

param DatasetType

[REQUIRED]

The type of the dataset. Specify train to create a training dataset. Specify test to create a test dataset.

type ProjectArn

string

param ProjectArn

[REQUIRED]

The ARN of the Amazon Rekognition Custom Labels project to which you want to asssign the dataset.

rtype

dict

returns

Response Syntax

{
    'DatasetArn': 'string'
}

Response Structure

  • (dict) --

    • DatasetArn (string) --

      The ARN of the created Amazon Rekognition Custom Labels dataset.

DescribeProjects (updated) Link ¶
Changes (request, response)
Request
{'ProjectNames': ['string']}
Response
{'ProjectDescriptions': {'Datasets': [{'CreationTimestamp': 'timestamp',
                                       'DatasetArn': 'string',
                                       'DatasetType': 'TRAIN | TEST',
                                       'Status': 'CREATE_IN_PROGRESS | '
                                                 'CREATE_COMPLETE | '
                                                 'CREATE_FAILED | '
                                                 'UPDATE_IN_PROGRESS | '
                                                 'UPDATE_COMPLETE | '
                                                 'UPDATE_FAILED | '
                                                 'DELETE_IN_PROGRESS',
                                       'StatusMessage': 'string',
                                       'StatusMessageCode': 'SUCCESS | '
                                                            'SERVICE_ERROR | '
                                                            'CLIENT_ERROR'}]}}

Gets information about your Amazon Rekognition Custom Labels projects.

This operation requires permissions to perform the rekognition:DescribeProjects action.

See also: AWS API Documentation

Request Syntax

client.describe_projects(
    NextToken='string',
    MaxResults=123,
    ProjectNames=[
        'string',
    ]
)
type NextToken

string

param NextToken

If the previous response was incomplete (because there is more results to retrieve), Amazon Rekognition Custom Labels returns a pagination token in the response. You can use this pagination token to retrieve the next set of results.

type MaxResults

integer

param MaxResults

The maximum number of results to return per paginated call. The largest value you can specify is 100. If you specify a value greater than 100, a ValidationException error occurs. The default value is 100.

type ProjectNames

list

param ProjectNames

A list of the projects that you want Amazon Rekognition Custom Labels to describe. If you don't specify a value, the response includes descriptions for all the projects in your AWS account.

  • (string) --

rtype

dict

returns

Response Syntax

{
    'ProjectDescriptions': [
        {
            'ProjectArn': 'string',
            'CreationTimestamp': datetime(2015, 1, 1),
            'Status': 'CREATING'|'CREATED'|'DELETING',
            'Datasets': [
                {
                    'CreationTimestamp': datetime(2015, 1, 1),
                    'DatasetType': 'TRAIN'|'TEST',
                    'DatasetArn': 'string',
                    'Status': 'CREATE_IN_PROGRESS'|'CREATE_COMPLETE'|'CREATE_FAILED'|'UPDATE_IN_PROGRESS'|'UPDATE_COMPLETE'|'UPDATE_FAILED'|'DELETE_IN_PROGRESS',
                    'StatusMessage': 'string',
                    'StatusMessageCode': 'SUCCESS'|'SERVICE_ERROR'|'CLIENT_ERROR'
                },
            ]
        },
    ],
    'NextToken': 'string'
}

Response Structure

  • (dict) --

    • ProjectDescriptions (list) --

      A list of project descriptions. The list is sorted by the date and time the projects are created.

      • (dict) --

        A description of an Amazon Rekognition Custom Labels project. For more information, see DescribeProjects.

        • ProjectArn (string) --

          The Amazon Resource Name (ARN) of the project.

        • CreationTimestamp (datetime) --

          The Unix timestamp for the date and time that the project was created.

        • Status (string) --

          The current status of the project.

        • Datasets (list) --

          Information about the training and test datasets in the project.

          • (dict) --

            Summary information for an Amazon Rekognition Custom Labels dataset. For more information, see ProjectDescription.

            • CreationTimestamp (datetime) --

              The Unix timestamp for the date and time that the dataset was created.

            • DatasetType (string) --

              The type of the dataset.

            • DatasetArn (string) --

              The Amazon Resource Name (ARN) for the dataset.

            • Status (string) --

              The status for the dataset.

            • StatusMessage (string) --

              The status message for the dataset.

            • StatusMessageCode (string) --

              The status message code for the dataset operation. If a service error occurs, try the API call again later. If a client error occurs, check the input parameters to the dataset API call that failed.

    • NextToken (string) --

      If the previous response was incomplete (because there is more results to retrieve), Amazon Rekognition Custom Labels returns a pagination token in the response. You can use this pagination token to retrieve the next set of results.