

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

# Mengubah file manifes SageMaker AI Ground Truth multi-label
<a name="md-gt-cl-transform"></a>

Topik ini menunjukkan kepada Anda cara mengubah file manifes Amazon SageMaker AI Ground Truth multi-label menjadi file manifes format Label Kustom Rekognition Amazon. 

SageMaker File manifes AI Ground Truth untuk pekerjaan multi-label diformat secara berbeda dari file manifes format Amazon Rekognition Custom Labels. Klasifikasi multi-label adalah ketika gambar diklasifikasikan ke dalam satu set kelas, tetapi mungkin milik beberapa kelas sekaligus. Dalam hal ini, gambar berpotensi memiliki beberapa label (multi-label), seperti *sepak bola* dan *bola*.

Untuk informasi tentang pekerjaan SageMaker AI Ground Truth multi-label, lihat [Klasifikasi Gambar (Multi-label](https://docs.aws.amazon.com/sagemaker/latest/dg/sms-image-classification-multilabel.html)). Untuk informasi tentang file manifes Label Kustom Amazon Rekognition format multi-label, lihat. [Menambahkan beberapa label tingkat gambar ke gambar](md-create-manifest-file-classification.md#md-dataset-purpose-classification-multiple-labels)

## Mendapatkan file manifes untuk pekerjaan SageMaker AI Ground Truth
<a name="md-get-gt-manifest"></a>

Prosedur berikut menunjukkan cara mendapatkan file manifes keluaran (`output.manifest`) untuk pekerjaan Amazon SageMaker AI Ground Truth. Anda menggunakan `output.manifest` sebagai masukan untuk prosedur berikutnya.

**Untuk mengunduh file manifes pekerjaan SageMaker AI Ground Truth**

1. Buka [https://console.aws.amazon.com/sagemaker/](https://console.aws.amazon.com/sagemaker/). 

1. Di panel navigasi, pilih **Ground Truth** lalu pilih **Labeling** Jobs. 

1. Pilih pekerjaan pelabelan yang berisi file manifes yang ingin Anda gunakan.

1. Pada halaman detail, pilih tautan di bawah **Lokasi set data keluaran**. Konsol Amazon S3 dibuka di lokasi dataset. 

1. Pilih`Manifests`, `output` dan kemudian`output.manifest`.

1. Pilih **Tindakan Objek** dan kemudian pilih **Unduh** untuk mengunduh file manifes.

## Mengubah file manifes SageMaker AI multi-label
<a name="md-transform-ml-gt"></a>

Prosedur berikut membuat file manifes Amazon Rekognition Custom Labels format multi-label dari file manifes AI format SageMaker GroundTruth multi-label yang ada.

**catatan**  
Untuk menjalankan kode, Anda memerlukan Python versi 3, atau lebih tinggi.<a name="md-procedure-multi-label-transform"></a>

**Untuk mengubah file manifes SageMaker AI multi-label**

1. Jalankan kode python berikut. Berikan nama file manifes yang Anda buat [Mendapatkan file manifes untuk pekerjaan SageMaker AI Ground Truth](#md-get-gt-manifest) sebagai argumen baris perintah.

   ```
   # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
   # SPDX-License-Identifier:  Apache-2.0
   """
   Purpose
   Shows how to create and Amazon Rekognition Custom Labels format
   manifest file from an Amazon SageMaker Ground Truth Image
   Classification (Multi-label) format manifest file.
   """
   import json
   import logging
   import argparse
   import os.path
   
   logger = logging.getLogger(__name__)
   
   def create_manifest_file(ground_truth_manifest_file):
       """
       Creates an Amazon Rekognition Custom Labels format manifest file from
       an Amazon SageMaker Ground Truth Image Classification (Multi-label) format
       manifest file.
       :param: ground_truth_manifest_file: The name of the Ground Truth manifest file,
       including the relative path.
       :return: The name of the new Custom Labels manifest file.
       """
   
       logger.info('Creating manifest file from %s', ground_truth_manifest_file)
       new_manifest_file = f'custom_labels_{os.path.basename(ground_truth_manifest_file)}'
   
       # Read the SageMaker Ground Truth manifest file into memory.
       with open(ground_truth_manifest_file) as gt_file:
           lines = gt_file.readlines()
   
       #Iterate through the lines one at a time to generate the
       #new lines for the Custom Labels manifest file.
       with open(new_manifest_file, 'w') as the_new_file:
           for line in lines:
               #job_name - The of the Amazon Sagemaker Ground Truth job.
               job_name = ''
               # Load in the old json item from the Ground Truth manifest file
               old_json = json.loads(line)
   
               # Get the job name
               keys = old_json.keys()
               for key in keys:
                   if 'source-ref' not in key and '-metadata' not in key:
                       job_name = key
   
               new_json = {}
               # Set the location of the image
               new_json['source-ref'] = old_json['source-ref']
   
               # Temporarily store the list of labels
               labels = old_json[job_name]
   
               # Iterate through the labels and reformat to Custom Labels format
               for index, label in enumerate(labels):
                   new_json[f'{job_name}{index}'] = index
                   metadata = {}
                   metadata['class-name'] = old_json[f'{job_name}-metadata']['class-map'][str(label)]
                   metadata['confidence'] = old_json[f'{job_name}-metadata']['confidence-map'][str(label)]
                   metadata['type'] = 'groundtruth/image-classification'
                   metadata['job-name'] = old_json[f'{job_name}-metadata']['job-name']
                   metadata['human-annotated'] = old_json[f'{job_name}-metadata']['human-annotated']
                   metadata['creation-date'] = old_json[f'{job_name}-metadata']['creation-date']
                   # Add the metadata to new json line
                   new_json[f'{job_name}{index}-metadata'] = metadata
               # Write the current line to the json file
               the_new_file.write(json.dumps(new_json))
               the_new_file.write('\n')
   
       logger.info('Created %s', new_manifest_file)
       return  new_manifest_file
   
   def add_arguments(parser):
       """
       Adds command line arguments to the parser.
       :param parser: The command line parser.
       """
   
       parser.add_argument(
           "manifest_file", help="The Amazon SageMaker Ground Truth manifest file"
           "that you want to use."
       )
   
   
   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()
           # Create the manifest file
           manifest_file = create_manifest_file(args.manifest_file)
           print(f'Manifest file created: {manifest_file}')
       except FileNotFoundError as err:
           logger.exception('File not found: %s', err)
           print(f'File not found: {err}. Check your manifest file.')
   
   if __name__ == "__main__":
       main()
   ```

1. Perhatikan nama file manifes baru yang ditampilkan skrip. Anda menggunakannya di langkah berikutnya.

1. [Unggah file manifes Anda](https://docs.aws.amazon.com/AmazonS3/latest/userguide/upload-objects.html) ke bucket Amazon S3 yang ingin Anda gunakan untuk menyimpan file manifes.
**catatan**  
Pastikan Label Kustom Amazon Rekognition memiliki akses ke bucket Amazon S3 yang direferensikan di bidang baris JSON file `source-ref` manifes. Untuk informasi selengkapnya, lihat [Mengakses Bucket Amazon S3 eksternal](su-console-policy.md#su-external-buckets). Jika lowongan Ground Truth menyimpan gambar di Bucket Konsol Label Kustom Amazon Rekognition, Anda tidak perlu menambahkan izin.

1. Ikuti petunjuk di [Membuat kumpulan data dengan file manifes SageMaker AI Ground Truth (Console)](md-create-dataset-ground-truth.md#md-create-dataset-ground-truth-console) untuk membuat kumpulan data dengan file manifes yang diunggah. Untuk langkah 8, di **lokasi file.manifest**, masukkan URL Amazon S3 untuk lokasi file manifes. Jika Anda menggunakan AWS SDK, lakukan[Membuat kumpulan data dengan file manifes SageMaker AI Ground Truth (SDK)](md-create-dataset-ground-truth.md#md-create-dataset-ground-truth-sdk).