删除 Amazon Rekognition Custom Labels 项目 - Rekognition

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

删除 Amazon Rekognition Custom Labels 项目

您可以使用亚马逊 Rekognition 控制台或调用 API 来删除项目。DeleteProject要删除项目,必须先删除所有关联的模型。已删除的项目或模型无法取消删除。

删除 Amazon Rekognition Custom Labels 项目(控制台)

您可以从项目页面删除项目,也可以从项目的详细信息页面删除项目。以下过程介绍了如何通过项目页面删除项目。

在删除项目的过程中,Amazon Rekognition Custom Labels 控制台会为您删除关联的模型和数据集。如果项目的任何模型正在运行或训练,则无法将其删除。要停止正在运行的模型,请参阅停止 Amazon Rekognition Custom Labels 模型 (SDK)。如果模型正在训练,请等到模型训练完成后再删除项目。

删除项目(控制台)
  1. 通过以下网址打开 Amazon Rekognition 控制台:https://console.aws.amazon.com/rekognition/

  2. 选择使用自定义标签

  3. 选择开始

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

  5. 项目页面上,选中要删除的项目对应的单选按钮。显示项目列表 echo-devices-project,其中有 1 个版本于 2020-03-25 创建,还有 “删除”、“训练新模型” 或 “创建项目” 选项。

    显示项目和 echo-devices-project 项目详细信息的项目列表。
  6. 在该页面的顶部,选择删除。随后会显示删除项目对话框。

  7. 如果项目没有关联的模型:

    1. 输入 delete 以删除项目。

    2. 选择删除以删除项目。

  8. 如果项目有关联的模型或数据集:

    1. 输入 delete 确认要删除这些模型和数据集。

    2. 根据项目是否具有数据集和/或模型,选择删除关联的模型删除关联的数据集删除关联的数据集和模型。模型删除可能需要一段时间才能完成。

      注意

      控制台无法删除正在训练或运行的模型。请停止列出的所有正在运行的模型,并等待列出为正在训练的模型完成训练,然后再试一次。

      如果在模型删除过程中关闭对话框,模型仍会被删除。稍后,您可以重复此过程来删除该项目。

      删除模型的面板为您提供了删除关联模型的明确说明。

      删除项目的接口。
    3. 输入 delete 确认要删除该项目。

    4. 选择删除以删除项目。

删除 Amazon Rekognition Custom Labels 项目 (SDK)

您可以通过DeleteProject调用并提供要删除的项目的亚马逊资源名称 (ARN) 来删除亚马逊 Rekognition 自定义标签项目。要在您的 AWS 账户中获取项目的 ARN,请致电DescribeProjects。响应包含一个ProjectDescription对象数组。项目 ARN 就是 ProjectArn 字段。可以使用项目名称来标识项目的 ARN。例如,arn:aws:rekognition:us-east-1:123456789010:project/project name/1234567890123

在删除项目之前,必须先删除项目中的所有模型和数据集。有关更多信息,请参阅 删除 Amazon Rekognition Custom Labels 模型 (SDK)删除数据集

项目可能需要几分钟才能删除。在此期间,项目状态为 DELETING。如果后续调用时DescribeProjects不包括您删除的项目,则该项目将被删除。

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

  2. 使用以下代码删除项目。

    AWS CLI

    project-arn 的值更改为要删除的项目的名称。

    aws rekognition delete-project --project-arn project_arn \ --profile custom-labels-access
    Python

    使用以下代码。提供以下命令行参数:

    • project_arn:要删除的项目的 ARN。

    # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 """ Purpose Amazon Rekognition Custom Labels project example used in the service documentation: https://docs.aws.amazon.com/rekognition/latest/customlabels-dg/mp-delete-project.html Shows how to delete an existing Amazon Rekognition Custom Labels project. You must first delete any models and datasets that belong to the project. """ import argparse import logging import time import boto3 from botocore.exceptions import ClientError logger = logging.getLogger(__name__) def find_forward_slash(input_string, n): """ Returns the location of '/' after n number of occurences. :param input_string: The string you want to search : n: the occurence that you want to find. """ position = input_string.find('/') while position >= 0 and n > 1: position = input_string.find('/', position + 1) n -= 1 return position def delete_project(rek_client, project_arn): """ Deletes an Amazon Rekognition Custom Labels project. :param rek_client: The Amazon Rekognition Custom Labels Boto3 client. :param project_arn: The ARN of the project that you want to delete. """ try: # Delete the project logger.info("Deleting project: %s", project_arn) response = rek_client.delete_project(ProjectArn=project_arn) logger.info("project status: %s",response['Status']) deleted = False logger.info("waiting for project deletion: %s", project_arn) # Get the project name start = find_forward_slash(project_arn, 1) + 1 end = find_forward_slash(project_arn, 2) project_name = project_arn[start:end] project_names = [project_name] while deleted is False: project_descriptions = rek_client.describe_projects( ProjectNames=project_names)['ProjectDescriptions'] if len(project_descriptions) == 0: deleted = True else: time.sleep(5) logger.info("project deleted: %s",project_arn) return True except ClientError as err: logger.exception( "Couldn't delete project - %s: %s", project_arn, 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 that you want to delete." ) 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"Deleting project: {args.project_arn}") # Delete the project. session = boto3.Session(profile_name='custom-labels-access') rekognition_client = session.client("rekognition") delete_project(rekognition_client, args.project_arn) print(f"Finished deleting project: {args.project_arn}") except ClientError as err: error_message = f"Problem deleting project: {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 java.util.List; import java.util.Objects; import java.util.logging.Level; import java.util.logging.Logger; 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.DeleteProjectRequest; import software.amazon.awssdk.services.rekognition.model.DeleteProjectResponse; import software.amazon.awssdk.services.rekognition.model.DescribeProjectsRequest; import software.amazon.awssdk.services.rekognition.model.DescribeProjectsResponse; import software.amazon.awssdk.services.rekognition.model.ProjectDescription; import software.amazon.awssdk.services.rekognition.model.RekognitionException; public class DeleteProject { public static final Logger logger = Logger.getLogger(DeleteProject.class.getName()); public static void deleteMyProject(RekognitionClient rekClient, String projectArn) throws InterruptedException { try { logger.log(Level.INFO, "Deleting project: {0}", projectArn); // Delete the project DeleteProjectRequest deleteProjectRequest = DeleteProjectRequest.builder().projectArn(projectArn).build(); DeleteProjectResponse response = rekClient.deleteProject(deleteProjectRequest); logger.log(Level.INFO, "Status: {0}", response.status()); // Wait until deletion finishes Boolean deleted = false; do { DescribeProjectsRequest describeProjectsRequest = DescribeProjectsRequest.builder().build(); DescribeProjectsResponse describeResponse = rekClient.describeProjects(describeProjectsRequest); List<ProjectDescription> projectDescriptions = describeResponse.projectDescriptions(); deleted = true; for (ProjectDescription projectDescription : projectDescriptions) { if (Objects.equals(projectDescription.projectArn(), projectArn)) { deleted = false; logger.log(Level.INFO, "Not deleted: {0}", projectDescription.projectArn()); Thread.sleep(5000); break; } } } while (Boolean.FALSE.equals(deleted)); logger.log(Level.INFO, "Project deleted: {0} ", projectArn); } catch ( RekognitionException e) { logger.log(Level.SEVERE, "Client error occurred: {0}", e.getMessage()); throw e; } } public static void main(String[] args) { final String USAGE = "\n" + "Usage: " + "<project_arn>\n\n" + "Where:\n" + " project_arn - The ARN of the project that you want to delete.\n\n"; if (args.length != 1) { System.out.println(USAGE); System.exit(1); } String projectArn = args[0]; try { RekognitionClient rekClient = RekognitionClient.builder() .region(Region.US_WEST_2) .credentialsProvider(ProfileCredentialsProvider.create("custom-labels-access")) .build(); // Delete the project. deleteMyProject(rekClient, projectArn); System.out.println(String.format("Project deleted: %s", projectArn)); rekClient.close(); } catch (RekognitionException rekError) { logger.log(Level.SEVERE, "Rekognition client error: {0}", rekError.getMessage()); System.exit(1); } catch (InterruptedException intError) { logger.log(Level.SEVERE, "Exception while sleeping: {0}", intError.getMessage()); System.exit(1); } } }