

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

# Menghapus model Label Kustom Rekognition Amazon
<a name="tm-delete-model"></a>

Anda dapat menghapus model dengan menggunakan konsol Amazon Rekognition Custom Labels atau dengan menggunakan API. [DeleteProjectVersion](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_DeleteProjectVersion) Anda tidak dapat menghapus model jika model sedang berjalan atau jika model sedang dalam pelatihan. Untuk menghentikan model yang sedang berjalan, gunakan [StopProjectVersion](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_StopProjectVersion)API. Untuk informasi selengkapnya, lihat [Menghentikan model Label Kustom Rekognition Amazon (SDK)](rm-stop.md#rm-stop-sdk). Jika model sedang dilatih, tunggu hingga selesai sebelum Anda menghapus model.

Model yang dihapus tidak dapat dihapus.

**Topics**
+ [Menghapus model Label Kustom Rekognition Amazon (Konsol)](#tm-delete-model-console)
+ [Menghapus model Label Kustom Rekognition Amazon (SDK)](#tm-delete-model-sdk)

## Menghapus model Label Kustom Rekognition Amazon (Konsol)
<a name="tm-delete-model-console"></a>

Prosedur berikut menunjukkan cara menghapus model dari halaman detail proyek. Anda juga dapat menghapus model dari halaman detail model. 

**Untuk menghapus model (konsol)**

1. Buka konsol Amazon Rekognition di. [https://console.aws.amazon.com/rekognition/](https://console.aws.amazon.com/rekognition/)

1. Pilih **Gunakan Label Kustom**.

1. Pilih **Mulai**. 

1. Di panel navigasi kiri, pilih **Proyek**.

1. Pilih proyek yang berisi model yang ingin Anda hapus. Halaman detail proyek terbuka.

1. Di bagian **Model**, pilih model yang ingin Anda hapus.
**catatan**  
Jika model tidak dapat dipilih, model sedang berjalan atau sedang dilatih, dan tidak dapat dihapus. Periksa bidang **Status** dan coba lagi setelah menghentikan model yang sedang berjalan, atau tunggu hingga pelatihan selesai. 

1. Pilih **Hapus model** dan **kotak dialog Delete model ditampilkan**.

1. Masukkan **hapus** untuk mengonfirmasi penghapusan. 

1. Pilih **Hapus** untuk menghapus model. Menghapus model mungkin perlu beberapa saat untuk diselesaikan.
**catatan**  
Jika Anda **Menutup** kotak dialog selama penghapusan model, model masih dihapus.

## Menghapus model Label Kustom Rekognition Amazon (SDK)
<a name="tm-delete-model-sdk"></a>

Anda menghapus model Label Kustom Rekognition Amazon dengan [DeleteProjectVersion](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_DeleteProjectVersion)memanggil dan memasok Nama Sumber Daya Amazon (ARN) model yang ingin Anda hapus. Anda bisa mendapatkan ARN model dari bagian **Use your model pada halaman detail model** di konsol Amazon Rekognition Custom Labels. Atau, hubungi [DescribeProjectVersions](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_DescribeProjectVersions)dan berikan yang berikut ini.
+ ARN proyek (`ProjectArn`) yang terkait dengan model tersebut.
+ Nama versi (`VersionNames`) dari model. 

Model ARN adalah `ProjectVersionArn` bidang dalam [ProjectVersionDescription](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_ProjectVersionDescription)objek, dari respons. `DescribeProjectVersions`

Anda tidak dapat menghapus model jika sedang berjalan atau sedang dilatih. Untuk menentukan apakah model sedang berjalan atau pelatihan, panggil [DescribeProjectVersions](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_DescribeProjectVersions)dan periksa `Status` bidang [ProjectVersionDescription](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_ProjectVersionDescription)objek model. Untuk menghentikan model yang sedang berjalan, gunakan [StopProjectVersion](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_StopProjectVersion)API. Untuk informasi selengkapnya, lihat [Menghentikan model Label Kustom Rekognition Amazon (SDK)](rm-stop.md#rm-stop-sdk). Anda harus menunggu model untuk menyelesaikan pelatihan sebelum Anda dapat menghapusnya. 

**Untuk menghapus model (SDK)**

1. Jika Anda belum melakukannya, instal dan konfigurasikan AWS CLI dan AWS SDKs. Untuk informasi selengkapnya, lihat [Langkah 4: Mengatur AWS CLI and AWS SDK](su-awscli-sdk.md).

1. Gunakan kode berikut untuk menghapus model. 

------
#### [ AWS CLI ]

   Ubah nilai `project-version-arn` menjadi nama proyek yang ingin Anda hapus.

   ```
   aws rekognition delete-project-version --project-version-arn {{model_arn}} \
     --profile custom-labels-access
   ```

------
#### [ Python ]

   Menyediakan parameter baris perintah berikut
   + `project_arn`— ARN dari proyek yang berisi model yang ingin Anda hapus.
   + `model_arn`— ARN dari versi model yang ingin Anda hapus.

   ```
   # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
   # SPDX-License-Identifier: Apache-2.0
   
   """
   Purpose
   Shows how to delete an existing Amazon Rekognition Custom Labels model.
   """
   
   
   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_model(rek_client, project_arn, model_arn):
       """
       Deletes an Amazon Rekognition Custom Labels model.
       :param rek_client: The Amazon Rekognition Custom Labels Boto3 client.
       :param model_arn: The ARN of the model version that you want to delete.
       """
   
       try:
           # Delete the model
           logger.info("Deleting dataset: {%s}", model_arn)
   
           rek_client.delete_project_version(ProjectVersionArn=model_arn)
   
           # Get the model version name
           start = find_forward_slash(model_arn, 3) + 1
           end = find_forward_slash(model_arn, 4)
           version_name = model_arn[start:end]
   
           deleted = False
   
           # model might not be deleted yet, so wait deletion finishes.
           while deleted is False:
               describe_response = rek_client.describe_project_versions(ProjectArn=project_arn,
                                                                        VersionNames=[version_name])
               if len(describe_response['ProjectVersionDescriptions']) == 0:
                   deleted = True
               else:
                   logger.info("Waiting for model deletion %s", model_arn)
                   time.sleep(5)
   
           logger.info("model deleted: %s", model_arn)
   
           return True
   
       except ClientError as err:
           logger.exception("Couldn't delete model - %s: %s",
                            model_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 contains the model that you want to delete."
       )
   
       parser.add_argument(
           "model_arn", help="The ARN of the model version that you want to delete."
       )
   
   
   def confirm_model_deletion(model_arn):
       """
       Confirms deletion of the model. Returns True if delete entered.
       :param model_arn: The ARN of the model that you want to delete.
       """
       print(f"Are you sure you wany to delete model {model_arn} ?\n", model_arn)
   
       start = input("Enter delete to delete your model: ")
       if start == "delete":
           return True
       else:
           return False
   
   
   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()
   
           if confirm_model_deletion(args.model_arn) is True:
               print(f"Deleting model: {args.model_arn}")
   
               # Delete the model.
               session = boto3.Session(profile_name='custom-labels-access')
               rekognition_client = session.client("rekognition")
   
               delete_model(rekognition_client,
                            args.project_arn,
                            args.model_arn)
   
               print(f"Finished deleting model: {args.model_arn}")
           else:
               print(f"Not deleting model {args.model_arn}")
   
       except ClientError as err:
           print(f"Problem deleting model: {err}")
   
   
   if __name__ == "__main__":
       main()
   ```

------
#### [ Java V2 ]
   + `project_arn`— ARN dari proyek yang berisi model yang ingin Anda hapus.
   + `model_arn`— ARN dari versi model yang ingin Anda hapus.

   ```
   //Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
   //PDX-License-Identifier: MIT-0 (For details, see https://github.com/awsdocs/amazon-rekognition-custom-labels-developer-guide/blob/master/LICENSE-SAMPLECODE.)
   
   import java.net.URI;
   import java.util.logging.Level;
   import java.util.logging.Logger;
   
   import software.amazon.awssdk.services.rekognition.RekognitionClient;
   
   import software.amazon.awssdk.services.rekognition.model.DeleteProjectVersionRequest;
   import software.amazon.awssdk.services.rekognition.model.DeleteProjectVersionResponse;
   import software.amazon.awssdk.services.rekognition.model.DescribeProjectVersionsRequest;
   import software.amazon.awssdk.services.rekognition.model.DescribeProjectVersionsResponse;
   import software.amazon.awssdk.services.rekognition.model.RekognitionException;
   
   public class DeleteModel {
   
       public static final Logger logger = Logger.getLogger(DeleteModel.class.getName());
   
       public static int findForwardSlash(String modelArn, int n) {
   
           int start = modelArn.indexOf('/');
           while (start >= 0 && n > 1) {
               start = modelArn.indexOf('/', start + 1);
               n -= 1;
           }
           return start;
   
       }
   
       public static void deleteMyModel(RekognitionClient rekClient, String projectArn, String modelArn)
               throws InterruptedException {
   
           try {
   
               logger.log(Level.INFO, "Deleting model: {0}", projectArn);
   
               // Delete the model
   
               DeleteProjectVersionRequest deleteProjectVersionRequest = DeleteProjectVersionRequest.builder()
                       .projectVersionArn(modelArn).build();
   
               DeleteProjectVersionResponse response =
                       rekClient.deleteProjectVersion(deleteProjectVersionRequest);
   
               logger.log(Level.INFO, "Status: {0}", response.status());
   
               // Get the model version
   
               int start = findForwardSlash(modelArn, 3) + 1;
               int end = findForwardSlash(modelArn, 4);
   
               String versionName = modelArn.substring(start, end);
   
               Boolean deleted = false;
   
               DescribeProjectVersionsRequest describeProjectVersionsRequest = DescribeProjectVersionsRequest.builder()
                       .projectArn(projectArn).versionNames(versionName).build();
   
               // Wait until model is deleted.
   
               do {
   
                   DescribeProjectVersionsResponse describeProjectVersionsResponse = rekClient
                           .describeProjectVersions(describeProjectVersionsRequest);
   
                   if (describeProjectVersionsResponse.projectVersionDescriptions().size()==0) {
                       logger.log(Level.INFO, "Waiting for model deletion: {0}", modelArn);
                       Thread.sleep(5000);
                   } else {
                       deleted = true;
                       logger.log(Level.INFO, "Model deleted: {0}", modelArn);
                   }
                   
               } while (Boolean.FALSE.equals(deleted));
   
               logger.log(Level.INFO, "Model deleted: {0}", modelArn);
   
           } 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> <model_arn>\n\n" + "Where:\n"
                   + "   project_arn - The ARN of the project that contains the model that you want to delete.\n\n"
                   + "   model_version - The ARN of the model that you want to delete.\n\n";
   
           if (args.length != 2) {
               System.out.println(USAGE);
               System.exit(1);
           }
   
           String projectArn = args[0];
           String modelVersion = args[1];
   
           try {
   
               RekognitionClient rekClient = RekognitionClient.builder().build();
   
               // Delete the model
               deleteMyModel(rekClient, projectArn, modelVersion);
   
               System.out.println(String.format("model deleted: %s", modelVersion));
   
               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);
           }
   
       }
   
   }
   ```

------