刪除資料集 - Rekognition

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

刪除資料集

您可以從專案中刪除訓練和測試資料集。

刪除資料集 (主控台)

使用下列程序來刪除資料集。之後,如果專案還剩下一個資料集 (訓練或測試),則會顯示專案詳細資料頁面。如果專案沒有剩餘的資料集,則會顯示「建立資料集」頁面。

如果您刪除訓練資料集,則必須先為專案建立新的訓練資料集,才能訓練模型。如需詳細資訊,請參閱建立包含影像的訓練和測試資料集

如果您刪除測試資料集,您可以訓練模型,而無需建立新的測試資料集。在訓練期間,會分割訓練資料集,以建立專案的新測試資料集。分割訓練資料集可減少可用於訓練的影像數量。為了維持品質,我們建議您在訓練模型之前先建立新的測試資料集。如需詳細資訊,請參閱將資料集新增至專案

刪除資料集
  1. 開啟亞馬遜重新認知主控台,網址為 https://console.aws.amazon.com/rekognition/

  2. 在左窗格中選擇使用自訂標籤。顯示 Amazon Rekognition 自訂標籤登陸頁面。

  3. 在左側導覽窗格中選擇 Projects (專案)。將顯示「專案」檢視。

  4. 選擇包含您要刪除之資料集的專案。

  5. 在左側導覽窗格中,在專案名稱 (專案名稱) 下,選擇 Datab et

  6. 選擇動作

  7. 若要刪除訓練資料集,請選擇 [刪除訓練資料集]。

  8. 若要刪除測試資料集,請選擇 [刪除測試資料集]。

  9. 在 [刪除訓練或測試資料集] 對話方塊中,輸入 delete 以確認您要刪除資料集。

  10. 選擇 [刪除訓練] 或 [測試資料集] 以刪除資料集。

刪除 Amazon Rekognition 自訂標籤資料集 (SDK)

資料集的 Amazon Rekognition ource Name (ARN),請先刪除 Amazon Resource Name (ARN)。DeleteDataset若要取得專案內訓練和測試資料集的 ARN,請呼叫DescribeProjects。該響應包括對ProjectDescription象的數組。資料集 ARN (DatasetArn) 和資料集類型 (DatasetType) 位於Datasets清單中。

如果您刪除訓練資料集,則需要先為專案建立新的訓練資料集,才能訓練模型。如果您刪除測試資料集,您必須先建立新的測試資料集,才能訓練模型。如需詳細資訊,請參閱將資料集新增至專案 (SDK)

若要刪除資料集 (SDK)
  1. 若果您尚未這樣做,請先完成安裝AWS CLI並設定和AWS SDK。如需詳細資訊,請參閱步驟 4:設定 AWS CLI 以及 AWS SDKs

  2. 使用下列程式碼來刪除資料集。

    AWS CLI

    dataset-arn使用您要刪除之資料集的 ARN。

    aws rekognition delete-dataset --dataset-arn dataset-arn \ --profile custom-labels-access
    Python

    使用下列程式碼。提供以下命令行參數:

    • 資料集-您要刪除之資料集的 ARN。

    # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 """ Purpose Shows how to delete an Amazon Rekognition Custom Labels dataset. """ import argparse import logging import time import boto3 from botocore.exceptions import ClientError logger = logging.getLogger(__name__) def delete_dataset(rek_client, dataset_arn): """ Deletes an Amazon Rekognition Custom Labels dataset. :param rek_client: The Amazon Rekognition Custom Labels Boto3 client. :param dataset_arn: The ARN of the dataset that you want to delete. """ try: # Delete the dataset, logger.info("Deleting dataset: %s", dataset_arn) rek_client.delete_dataset(DatasetArn=dataset_arn) deleted = False logger.info("waiting for dataset deletion %s", dataset_arn) # Dataset might not be deleted yet, so wait. while deleted is False: try: rek_client.describe_dataset(DatasetArn=dataset_arn) time.sleep(5) except ClientError as err: if err.response['Error']['Code'] == 'ResourceNotFoundException': logger.info("dataset deleted: %s", dataset_arn) deleted = True else: raise logger.info("dataset deleted: %s", dataset_arn) return True except ClientError as err: logger.exception("Couldn't delete dataset - %s: %s", dataset_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( "dataset_arn", help="The ARN of the dataset 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 dataset: {args.dataset_arn}") # Delete the dataset. session = boto3.Session(profile_name='custom-labels-access') rekognition_client = session.client("rekognition") delete_dataset(rekognition_client, args.dataset_arn) print(f"Finished deleting dataset: {args.dataset_arn}") except ClientError as err: error_message = f"Problem deleting dataset: {err}" logger.exception(error_message) print(error_message) if __name__ == "__main__": main()
    Java V2

    使用下列程式碼。提供以下命令行參數:

    • 資料集-您要刪除之資料集的 ARN。

    /* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 */ package com.example.rekognition; 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.DeleteDatasetRequest; import software.amazon.awssdk.services.rekognition.model.DeleteDatasetResponse; import software.amazon.awssdk.services.rekognition.model.DescribeDatasetRequest; import software.amazon.awssdk.services.rekognition.model.RekognitionException; public class DeleteDataset { public static final Logger logger = Logger.getLogger(DeleteDataset.class.getName()); public static void deleteMyDataset(RekognitionClient rekClient, String datasetArn) throws InterruptedException { try { logger.log(Level.INFO, "Deleting dataset: {0}", datasetArn); // Delete the dataset DeleteDatasetRequest deleteDatasetRequest = DeleteDatasetRequest.builder().datasetArn(datasetArn).build(); DeleteDatasetResponse response = rekClient.deleteDataset(deleteDatasetRequest); // Wait until deletion finishes DescribeDatasetRequest describeDatasetRequest = DescribeDatasetRequest.builder().datasetArn(datasetArn) .build(); Boolean deleted = false; do { try { rekClient.describeDataset(describeDatasetRequest); Thread.sleep(5000); } catch (RekognitionException e) { String errorCode = e.awsErrorDetails().errorCode(); if (errorCode.equals("ResourceNotFoundException")) { logger.log(Level.INFO, "Dataset deleted: {0}", datasetArn); deleted = true; } else { logger.log(Level.SEVERE, "Client error occurred: {0}", e.getMessage()); throw e; } } } while (Boolean.FALSE.equals(deleted)); logger.log(Level.INFO, "Dataset deleted: {0} ", datasetArn); } 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: " + "<dataset_arn>\n\n" + "Where:\n" + " dataset_arn - The ARN of the dataset that you want to delete.\n\n"; if (args.length != 1) { System.out.println(USAGE); System.exit(1); } String datasetArn = args[0]; try { // Get the Rekognition client. RekognitionClient rekClient = RekognitionClient.builder() .credentialsProvider(ProfileCredentialsProvider.create("custom-labels-access")) .region(Region.US_WEST_2) .build(); // Delete the dataset deleteMyDataset(rekClient, datasetArn); System.out.println(String.format("Dataset deleted: %s", datasetArn)); 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); } } }