Amazon Rekognition Custom Labels プロジェクトの削除 - Rekognition

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

Amazon Rekognition Custom Labels プロジェクトの削除

プロジェクトを削除するには、Amazon Rekognition コンソールを使用するか、 DeleteProject API を呼び出します。プロジェクトを削除するには、最初に関連付けられたモデルをすべて削除する必要があります。削除したプロジェクトを元に戻すことはできません。

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. [プロジェクト] ページで、削除するプロジェクトのラジオボタンを選択します。2020-03-25 に作成されたバージョンが 1 つで、削除 echo-devices-project、新しいモデルのトレーニング、またはプロジェクトの作成のオプションを含む を示すプロジェクトリスト。

    プロジェクトと echo-devices-project プロジェクトの詳細を示すプロジェクトリスト。
  6. ページの上部で、[削除] を選択します。[プロジェクトを削除] ダイアログボックスが表示されます。

  7. モデルに関連付けられたモデルがない場合:

    1. [delete] と入力して、プロジェクトを削除します。

    2. [削除] を選択して、プロジェクトを削除します。

  8. モデルに関連付けられたモデルがある場合:

    1. [delete] と入力して、削除するモデルとモデルを確認します。

    2. モデルにデータセット、モデル、またはその両方が含まれているかどうかに応じて、[関連付けられたデータセットを削除][関連付けられたモデルを削除]、または [関連付けられたデータセットとモデルを削除] を選択します。モデルの削除が完了するまでに時間がかかる場合があります。

      注記

      コンソールでは、トレーニング中または実行中のモデルを削除することはできません。一覧表示されている実行中のモデルを停止してから再試行するか、トレーニングが終了するまで待ちます。

      モデルの削除中にダイアログボックスを閉じた場合でも、モデルは削除されます。後で、この手順を繰り返すことにより、プロジェクトを削除できます。

      モデルを削除するためのパネルには、関連するモデルを削除する明示的な手順が表示されます。

      プロジェクトを削除するためのインターフェイス。
    3. [delete] と入力して、削除するプロジェクトを確認します。

    4. [削除] を選択して、プロジェクトを削除します。

Amazon Rekognition Custom Labels プロジェクトの削除 (SDK)

Amazon Rekognition Custom Labels プロジェクトを削除するには、 を呼び出しDeleteProject、削除するプロジェクトの Amazon リソースネーム (ARN) を指定します。 AWS アカウント内のプロジェクトの ARNs を取得するには、 を呼び出します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 SDKsをインストール AWS CLI して設定します。詳細については、「ステップ 4: AWS CLI と AWS SDKsを設定する」を参照してください。

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