モデルの記述 (SDK) - Rekognition

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

モデルの記述 (SDK)

DescribeProjectVersions API を使用して、モデルのバージョンに関する情報を取得できます。VersionName を指定しないと、DescribeProjectVersions はプロジェクト内のすべてのモデルバージョンの記述を返します。

モデルを記述するには (SDK)
  1. 現時点で AWS CLI と AWS SDK のインストールと設定が完了していない場合は、インストールと設定を実行します。詳細については、「ステップ 4: をセットアップする AWS CLI また、 AWS SDKs」を参照してください。

  2. 次のサンプルコードを使用して、モデルのバージョンを記述します。

    AWS CLI

    project-arn の値を、記述するプロジェクトの ARN に変更します。version-name の値を、記述するするモデルのバージョンに変更します。

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

    次のコードを使用します。次のコマンドラインパラメータを指定します。

    • project_arn - 記述するモデルの ARN。

    • model_version - 記述するモデルのバージョン。

    例: 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

    次のコードを使用します。次のコマンドラインパラメータを指定します。

    • project_arn - 記述するモデルの ARN。

    • model_version - 記述するモデルのバージョン。

    /* 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); } } }