描述一個模型(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。

    • 模型 _ 版本-您想要您想要描述的模型版本。

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

    • 模型 _ 版本-您想要您想要描述的模型版本。

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