Describing a dataset (SDK)
You can use the DescribeDataset
API to get information about a
dataset.
To describe a dataset (SDK)
-
If you haven't already done so, install and configure the AWS CLI and the AWS SDKs. For more information, see Step 4: Set up the AWS CLI and AWS SDKs.
-
Use the following example code to describe a dataset.
- AWS CLI
-
Change the value of
dataset-arn
to the ARN of the dataset that you want to describe.aws rekognition describe-dataset --dataset-arn
dataset_arn
\ --profile custom-labels-access - Python
-
Use the following code. Supply the following command line parameters:
-
dataset_arn — the ARN of the dataset that you want to describe.
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 """ Purpose Shows how to describe an Amazon Rekognition Custom Labels dataset. """ import argparse import logging import boto3 from botocore.exceptions import ClientError logger = logging.getLogger(__name__) def describe_dataset(rek_client, dataset_arn): """ Describes an Amazon Rekognition Custom Labels dataset. :param rek_client: The Amazon Rekognition Custom Labels Boto3 client. :param dataset_arn: The ARN of the dataset that you want to describe. """ try: # Describe the dataset logger.info("Describing dataset %s", dataset_arn) dataset = rek_client.describe_dataset(DatasetArn=dataset_arn) description = dataset['DatasetDescription'] print(f"Created: {str(description['CreationTimestamp'])}") print(f"Updated: {str(description['LastUpdatedTimestamp'])}") print(f"Status: {description['Status']}") print(f"Status message: {description['StatusMessage']}") print(f"Status code: {description['StatusMessageCode']}") print("Stats:") print( f"\tLabeled entries: {description['DatasetStats']['LabeledEntries']}") print( f"\tTotal entries: {description['DatasetStats']['TotalEntries']}") print(f"\tTotal labels: {description['DatasetStats']['TotalLabels']}") except ClientError as err: logger.exception("Couldn't describe dataset: %s", err.response['Error']['Message']) raise def add_arguments(parser): """ Adds command line arguments to the parser. :param parser: The command line parser. """ parser.add_argument( "dataset_arn", help="The ARN of the dataset that you want to describe." ) def main(): logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s") try: # Get command line arguments. parser = argparse.ArgumentParser(usage=argparse.SUPPRESS) add_arguments(parser) args = parser.parse_args() print(f"Describing dataset {args.dataset_arn}") # Describe the dataset. session = boto3.Session(profile_name='custom-labels-access') rekognition_client = session.client("rekognition") describe_dataset(rekognition_client, args.dataset_arn) print(f"Finished describing dataset: {args.dataset_arn}") except ClientError as err: error_message=f"Problem describing dataset: {err}" logger.exception(error_message) print(error_message) except Exception as err: error_message = f"Problem describing dataset: {err}" logger.exception(error_message) print(error_message) if __name__ == "__main__": main()
-
- Java V2
-
-
dataset_arn — the ARN of the dataset that you want to describe.
/* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 */ package com.example.rekognition; import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider; import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.rekognition.RekognitionClient; import software.amazon.awssdk.services.rekognition.model.DatasetDescription; import software.amazon.awssdk.services.rekognition.model.DatasetStats; import software.amazon.awssdk.services.rekognition.model.DescribeDatasetRequest; import software.amazon.awssdk.services.rekognition.model.DescribeDatasetResponse; import software.amazon.awssdk.services.rekognition.model.RekognitionException; import java.util.logging.Level; import java.util.logging.Logger; public class DescribeDataset { public static final Logger logger = Logger.getLogger(DescribeDataset.class.getName()); public static void describeMyDataset(RekognitionClient rekClient, String datasetArn) { try { DescribeDatasetRequest describeDatasetRequest = DescribeDatasetRequest.builder().datasetArn(datasetArn) .build(); DescribeDatasetResponse describeDatasetResponse = rekClient.describeDataset(describeDatasetRequest); DatasetDescription datasetDescription = describeDatasetResponse.datasetDescription(); DatasetStats datasetStats = datasetDescription.datasetStats(); System.out.println("ARN: " + datasetArn); System.out.println("Created: " + datasetDescription.creationTimestamp().toString()); System.out.println("Updated: " + datasetDescription.lastUpdatedTimestamp().toString()); System.out.println("Status: " + datasetDescription.statusAsString()); System.out.println("Message: " + datasetDescription.statusMessage()); System.out.println("Total Labels: " + datasetStats.totalLabels().toString()); System.out.println("Total entries: " + datasetStats.totalEntries().toString()); System.out.println("Entries with labels: " + datasetStats.labeledEntries().toString()); System.out.println("Entries with at least 1 error: " + datasetStats.errorEntries().toString()); } catch (RekognitionException rekError) { logger.log(Level.SEVERE, "Rekognition client error: {0}", rekError.getMessage()); throw rekError; } } public static void main(String[] args) { final String USAGE = "\n" + "Usage: " + "<dataset_arn>\n\n" + "Where:\n" + " dataset_arn - The ARN of the dataset that you want to describe.\n\n"; if (args.length != 1) { System.out.println(USAGE); System.exit(1); } String datasetArn = args[0]; try { // Get the Rekognition client. RekognitionClient rekClient = RekognitionClient.builder() .credentialsProvider(ProfileCredentialsProvider.create("custom-labels-access")) .region(Region.US_WEST_2) .build(); // Describe the dataset. describeMyDataset(rekClient, datasetArn); rekClient.close(); } catch (RekognitionException rekError) { logger.log(Level.SEVERE, "Rekognition client error: {0}", rekError.getMessage()); System.exit(1); } } }
-
Creating a dataset using an existing dataset (SDK)
Listing dataset entries (SDK)