Décrire un modèle (SDK) - Rekognition

Les traductions sont fournies par des outils de traduction automatique. En cas de conflit entre le contenu d'une traduction et celui de la version originale en anglais, la version anglaise prévaudra.

Décrire un modèle (SDK)

Vous pouvez utiliser l'DescribeProjectVersionsAPI pour obtenir des informations sur une version d'un modèle. Si vous ne le spécifiez pasVersionName,DescribeProjectVersions renvoie les descriptions de toutes les versions du modèle du projet.

Pour décrire un modèle (SDK)
  1. Si vous ne l'avez pas déjà fait, installez et configurez lesAWS SDKAWS CLI et. Pour plus d'informations, veuillez consulter Étape 4 : Configurez le AWS CLI and AWS SDKs.

  2. Utilisez l'exemple de code suivant pour décrire une version d'un modèle.

    AWS CLI

    Remplacez la valeurproject-arn de par l'ARN du projet que vous souhaitez décrire. Remplacez la valeurversion-name de par la version du modèle que vous souhaitez décrire.

    aws rekognition describe-project-versions --project-arn project_arn \ --version-names version_name \ --profile custom-labels-access
    Python

    Utilisez le code suivant : Fournissez les paramètres de ligne de commande suivants :

    • project_arn — L'ARN du modèle que vous voulez décrire.

    • model_version — version du modèle que vous souhaitez décrire.

    Par exemple : python describe_model.py project_arn model_version

    # 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 model. """ import argparse import logging import boto3 from botocore.exceptions import ClientError logger = logging.getLogger(__name__) def describe_model(rek_client, project_arn, version_name): """ Describes an Amazon Rekognition Custom Labels model. :param rek_client: The Amazon Rekognition Custom Labels Boto3 client. :param project_arn: The ARN of the prject that contains the model. :param version_name: The version name of the model that you want to describe. """ try: # Describe the model logger.info("Describing model: %s for project %s", version_name, project_arn) describe_response = rek_client.describe_project_versions(ProjectArn=project_arn, VersionNames=[version_name]) for model in describe_response['ProjectVersionDescriptions']: print(f"Created: {str(model['CreationTimestamp'])} ") print(f"ARN: {str(model['ProjectVersionArn'])} ") if 'BillableTrainingTimeInSeconds' in model: print( f"Billing training time (minutes): {str(model['BillableTrainingTimeInSeconds']/60)} ") print("Evaluation results: ") if 'EvaluationResult' in model: evaluation_results = model['EvaluationResult'] print(f"\tF1 score: {str(evaluation_results['F1Score'])}") print( f"\tSummary location: s3://{evaluation_results['Summary']['S3Object']['Bucket']}/{evaluation_results['Summary']['S3Object']['Name']}") if 'ManifestSummary' in model: print( f"Manifest summary location: s3://{model['ManifestSummary']['S3Object']['Bucket']}/{model['ManifestSummary']['S3Object']['Name']}") if 'OutputConfig' in model: print( f"Training output location: s3://{model['OutputConfig']['S3Bucket']}/{model['OutputConfig']['S3KeyPrefix']}") if 'MinInferenceUnits' in model: print( f"Minimum inference units: {str(model['MinInferenceUnits'])}") if 'MaxInferenceUnits' in model: print( f"Maximum Inference units: {str(model['MaxInferenceUnits'])}") print("Status: " + model['Status']) print("Message: " + model['StatusMessage']) except ClientError as err: logger.exception( "Couldn't describe model: %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( "project_arn", help="The ARN of the project in which the model resides." ) parser.add_argument( "version_name", help="The version of the model 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 model: {args.version_name} for project {args.project_arn}.") # Describe the model. session = boto3.Session(profile_name='custom-labels-access') rekognition_client = session.client("rekognition") describe_model(rekognition_client, args.project_arn, args.version_name) print( f"Finished describing model: {args.version_name} for project {args.project_arn}.") except ClientError as err: error_message = f"Problem describing model: {err}" logger.exception(error_message) print(error_message) except Exception as err: error_message = f"Problem describing model: {err}" logger.exception(error_message) print(error_message) if __name__ == "__main__": main()
    Java V2

    Utilisez le code suivant : Fournissez les paramètres de ligne de commande suivants :

    • project_arn — L'ARN du modèle que vous voulez décrire.

    • model_version — version du modèle que vous souhaitez décrire.

    /* 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.DescribeProjectVersionsRequest; import software.amazon.awssdk.services.rekognition.model.DescribeProjectVersionsResponse; import software.amazon.awssdk.services.rekognition.model.EvaluationResult; import software.amazon.awssdk.services.rekognition.model.GroundTruthManifest; import software.amazon.awssdk.services.rekognition.model.OutputConfig; import software.amazon.awssdk.services.rekognition.model.ProjectVersionDescription; import software.amazon.awssdk.services.rekognition.model.RekognitionException; import java.util.logging.Level; import java.util.logging.Logger; public class DescribeModel { public static final Logger logger = Logger.getLogger(DescribeModel.class.getName()); public static void describeMyModel(RekognitionClient rekClient, String projectArn, String versionName) { try { // If a single version name is supplied, build request argument DescribeProjectVersionsRequest describeProjectVersionsRequest = null; if (versionName == null) { describeProjectVersionsRequest = DescribeProjectVersionsRequest.builder().projectArn(projectArn) .build(); } else { describeProjectVersionsRequest = DescribeProjectVersionsRequest.builder().projectArn(projectArn) .versionNames(versionName).build(); } DescribeProjectVersionsResponse describeProjectVersionsResponse = rekClient .describeProjectVersions(describeProjectVersionsRequest); for (ProjectVersionDescription projectVersionDescription : describeProjectVersionsResponse .projectVersionDescriptions()) { System.out.println("ARN: " + projectVersionDescription.projectVersionArn()); System.out.println("Status: " + projectVersionDescription.statusAsString()); System.out.println("Message: " + projectVersionDescription.statusMessage()); if (projectVersionDescription.billableTrainingTimeInSeconds() != null) { System.out.println( "Billable minutes: " + (projectVersionDescription.billableTrainingTimeInSeconds() / 60)); } if (projectVersionDescription.evaluationResult() != null) { EvaluationResult evaluationResult = projectVersionDescription.evaluationResult(); System.out.println("F1 Score: " + evaluationResult.f1Score()); System.out.println("Summary location: s3://" + evaluationResult.summary().s3Object().bucket() + "/" + evaluationResult.summary().s3Object().name()); } if (projectVersionDescription.manifestSummary() != null) { GroundTruthManifest manifestSummary = projectVersionDescription.manifestSummary(); System.out.println("Manifest summary location: s3://" + manifestSummary.s3Object().bucket() + "/" + manifestSummary.s3Object().name()); } if (projectVersionDescription.outputConfig() != null) { OutputConfig outputConfig = projectVersionDescription.outputConfig(); System.out.println( "Training output: s3://" + outputConfig.s3Bucket() + "/" + outputConfig.s3KeyPrefix()); } if (projectVersionDescription.minInferenceUnits() != null) { System.out.println("Min inference units: " + projectVersionDescription.minInferenceUnits()); } System.out.println(); } } catch (RekognitionException rekError) { logger.log(Level.SEVERE, "Rekognition client error: {0}", rekError.getMessage()); throw rekError; } } public static void main(String args[]) { String projectArn = null; String versionName = null; final String USAGE = "\n" + "Usage: " + "<project_arn> <version_name>\n\n" + "Where:\n" + " project_arn - The ARN of the project that contains the models you want to describe.\n\n" + " version_name - (optional) The version name of the model that you want to describe. \n\n" + " If you don't specify a value, all model versions are described.\n\n"; if (args.length > 2 || args.length == 0) { System.out.println(USAGE); System.exit(1); } projectArn = args[0]; if (args.length == 2) { versionName = args[1]; } try { // Get the Rekognition client. RekognitionClient rekClient = RekognitionClient.builder() .credentialsProvider(ProfileCredentialsProvider.create("custom-labels-access")) .region(Region.US_WEST_2) .build(); // Describe the model describeMyModel(rekClient, projectArn, versionName); rekClient.close(); } catch (RekognitionException rekError) { logger.log(Level.SEVERE, "Rekognition client error: {0}", rekError.getMessage()); System.exit(1); } } }