本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
描述模型 (SDK)
可以使用 DescribeProjectVersions
API 获取有关模型版本的信息。如果不指定 VersionName
,DescribeProjectVersions
会返回项目中所有模型版本的描述。
描述模型 (SDK)
-
安装并配置 AWS CLI 和 AWS SDK(如果尚未如此)。有关更多信息,请参阅步骤 4:设置 AWS CLI 以及 AWS SDKs。
-
使用以下示例代码描述模型版本。
- AWS CLI
-
将
project-arn
的值更改为要描述的项目的 ARN。将version-name
的值更改为要描述的模型的版本。aws rekognition describe-project-versions --project-arn
project_arn
\ --version-namesversion_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); } } }
-
标记模型
复制模型 (SDK)