创建项目 - Rekognition

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

创建项目

项目用于管理模型的模型版本、训练数据集和测试数据集。可以使用 Amazon Rekognition Custom Labels 控制台或 API 创建项目。有关其他项目任务(例如删除项目),请参阅管理 Amazon Rekognition Custom Labels 项目

您可以使用标签对您的 Amazon Rekognition 自定义标签资源进行分类和管理,包括您的项目。

CreateProject操作允许您在创建新项目时选择性地指定标签,将标签作为键值对提供,可用于对资源进行分类和管理。

创建 Amazon Rekognition Custom Labels 项目(控制台)

可以使用 Amazon Rekognition Custom Labels 控制台创建项目。首次在新 AWS 区域使用控制台时,Amazon Rekognition 自定义标签会要求在您的账户中创建一个 Amazon S3 存储桶(控制台存储桶)。 AWS 该存储桶用于存储您的项目文件。必须创建控制台存储桶,才能使用 Amazon Rekognition Custom Labels 控制台。

可以使用 Amazon Rekognition Custom Labels 控制台创建项目。

创建项目(控制台)
  1. 登录 AWS Management Console 并打开亚马逊 Rekognition 控制台,网址为 https://console.aws.amazon.com/rekognition/。

  2. 在左侧窗格中,选择使用自定义标签。随后将显示 Amazon Rekognition Custom Labels 登录页面。

  3. 在 Amazon Rekognition Custom Labels 登录页面上,选择开始

  4. 在左侧窗格中,选择项目

  5. 选择创建项目

  6. 项目名称中输入项目名称。

  7. 选择创建项目,创建您的项目。

  8. 按照创建训练和测试数据集中的步骤为项目创建训练和测试数据集。

创建 Amazon Rekognition Custom Labels 项目 (SDK)

您可以通过调用来创建 Amazon Rekognition 自定义标签项目。CreateProject响应是标识项目的 Amazon 资源名称 (ARN)。创建项目后,可以创建用于训练和测试模型的数据集。有关更多信息,请参阅 使用图像创建训练和测试数据集

创建项目 (SDK)
  1. 如果您尚未这样做,请安装和配置和 AWS SDK。 AWS CLI 有关更多信息,请参阅 步骤 4:设置 AWS CLI 和 AWS 软件开发工具包

  2. 使用以下代码创建项目。

    AWS CLI

    以下示例会创建一个项目并显示其 ARN。

    project-name 的值更改为要创建的项目的名称。

    aws rekognition create-project --project-name my_project \ --profile custom-labels-access --"CUSTOM_LABELS" --tags'{"key1":"value1","key2":"value2"}'
    Python

    以下示例会创建一个项目并显示其 ARN。提供以下命令行参数:

    • project_name:要创建的项目的名称。

    # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 import argparse import logging import boto3 from botocore.exceptions import ClientError logger = logging.getLogger(__name__) def create_project(rek_client, project_name): """ Creates an Amazon Rekognition Custom Labels project :param rek_client: The Amazon Rekognition Custom Labels Boto3 client. :param project_name: A name for the new prooject. """ try: #Create the project. logger.info("Creating project: %s",project_name) response=rek_client.create_project(ProjectName=project_name) logger.info("project ARN: %s",response['ProjectArn']) return response['ProjectArn'] except ClientError as err: logger.exception("Couldn't create project - %s: %s", project_name, 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_name", help="A name for the new project." ) 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"Creating project: {args.project_name}") # Create the project. session = boto3.Session(profile_name='custom-labels-access') rekognition_client = session.client("rekognition") project_arn=create_project(rekognition_client, args.project_name) print(f"Finished creating project: {args.project_name}") print(f"ARN: {project_arn}") except ClientError as err: logger.exception("Problem creating project: %s", err) print(f"Problem creating project: {err}") if __name__ == "__main__": main()
    Java V2

    以下示例会创建一个项目并显示其 ARN。

    提供以下命令行参数:

    • project_name:要创建的项目的名称。

    /* 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.CreateProjectRequest; import software.amazon.awssdk.services.rekognition.model.CreateProjectResponse; import software.amazon.awssdk.services.rekognition.model.RekognitionException; import java.util.logging.Level; import java.util.logging.Logger; public class CreateProject { public static final Logger logger = Logger.getLogger(CreateProject.class.getName()); public static String createMyProject(RekognitionClient rekClient, String projectName) { try { logger.log(Level.INFO, "Creating project: {0}", projectName); CreateProjectRequest createProjectRequest = CreateProjectRequest.builder().projectName(projectName).build(); CreateProjectResponse response = rekClient.createProject(createProjectRequest); logger.log(Level.INFO, "Project ARN: {0} ", response.projectArn()); return response.projectArn(); } catch (RekognitionException e) { logger.log(Level.SEVERE, "Could not create project: {0}", e.getMessage()); throw e; } } public static void main(String[] args) { final String USAGE = "\n" + "Usage: " + "<project_name> <bucket> <image>\n\n" + "Where:\n" + " project_name - A name for the new project\n\n"; if (args.length != 1) { System.out.println(USAGE); System.exit(1); } String projectName = args[0]; String projectArn = null; ; try { // Get the Rekognition client. RekognitionClient rekClient = RekognitionClient.builder() .credentialsProvider(ProfileCredentialsProvider.create("custom-labels-access")) .region(Region.US_WEST_2) .build(); // Create the project projectArn = createMyProject(rekClient, projectName); System.out.println(String.format("Created project: %s %nProject ARN: %s", projectName, projectArn)); rekClient.close(); } catch (RekognitionException rekError) { logger.log(Level.SEVERE, "Rekognition client error: {0}", rekError.getMessage()); System.exit(1); } } }
  3. 记下响应中显示的项目 ARN 的名称。您将需要它来创建模型。

  4. 按照创建训练和测试数据集 (SDK) 中的步骤为项目创建训练和测试数据集。

CreateProject 操作请求

以下是 CreateProject 操作请求的格式:

{ "AutoUpdate": "string", "Feature": "string", "ProjectName": "string", "Tags": { "string": "string" } }