Menambahkan lebih banyak gambar ke dataset - Rekognition

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

Menambahkan lebih banyak gambar ke dataset

Anda dapat menambahkan lebih banyak gambar ke kumpulan data Anda dengan menggunakan konsol Amazon Rekognition Custom Labels atau dengan memanggilUpdateDatasetEntries API.

Menambahkan lebih banyak gambar (konsol)

Saat Anda menggunakan konsol Amazon Rekognition Custom Labels, Anda mengunggah gambar dari komputer lokal. Gambar ditambahkan ke lokasi bucket Amazon S3 (konsol atau eksternal) tempat gambar yang digunakan untuk membuat kumpulan data disimpan.

Untuk menambahkan lebih banyak gambar ke set data Anda (konsol)
  1. Buka konsol Amazon Rekognition di https://console.aws.amazon.com/rekognition/.

  2. Di panel sebelah kiri, pilih Gunakan Label Kustom. Halaman arahan Amazon Rekognition Custom Labels ditampilkan.

  3. Di panel navigasi kiri, pilih Proyek. Tampilan Proyek ditampilkan.

  4. Pilih proyek yang ingin Anda gunakan.

  5. Di panel navigasi kiri kiri kiri kiri kiri kiri kiri kiri kiri kiri, pilih Set Data.

  6. Pilih Actions dan pilih set data yang ingin Anda tambahkan gambar.

  7. Pilih gambar yang ingin Anda unggah ke set data. Anda dapat menyeret gambar atau memilih gambar yang ingin Anda unggah dari komputer lokal Anda. Anda dapat mengunggah hingga 30 gambar sekaligus.

  8. Pilih Unggah gambar.

  9. Pilih Save changes (Simpan perubahan).

  10. Beri label pada gambar. Untuk informasi selengkapnya, lihat Pelabelan gambar.

Menambahkan lebih banyak gambar (SDK)

UpdateDatasetEntriesmemperbarui atau menambahkan baris JSON ke file manifes. Anda melewati baris JSON sebagai objek data byte64 dikodekan diGroundTruth lapangan. Jika Anda menggunakanAWS SDK untuk meneleponUpdateDatasetEntries, SDK akan mengkodekan data untuk Anda. Setiap baris JSON berisi informasi untuk satu gambar, seperti label yang ditetapkan atau informasi kotak pembatas. Misalnya:

{"source-ref":"s3://bucket/image","BB":{"annotations":[{"left":1849,"top":1039,"width":422,"height":283,"class_id":0},{"left":1849,"top":1340,"width":443,"height":415,"class_id":1},{"left":2637,"top":1380,"width":676,"height":338,"class_id":2},{"left":2634,"top":1051,"width":673,"height":338,"class_id":3}],"image_size":[{"width":4000,"height":2667,"depth":3}]},"BB-metadata":{"job-name":"labeling-job/BB","class-map":{"0":"comparator","1":"pot_resistor","2":"ir_phototransistor","3":"ir_led"},"human-annotated":"yes","objects":[{"confidence":1},{"confidence":1},{"confidence":1},{"confidence":1}],"creation-date":"2021-06-22T10:11:18.006Z","type":"groundtruth/object-detection"}}

Untuk informasi selengkapnya, lihat Membuat file manifes.

Gunakansource-ref kolom sebagai kunci untuk mengidentifikasi gambar yang ingin Anda perbarui. Jika dataset tidak berisi nilaisource-ref bidang yang cocok, baris JSON ditambahkan sebagai gambar baru.

Untuk menambahkan lebih banyak gambar ke dataset (SDK)
  1. Jika Anda belum melakukannya, instal dan konfigurasikanAWS CLI danAWS SDK. Untuk informasi selengkapnya, lihat Langkah 4: Siapkan AWS CLI and AWS SDKs.

  2. Gunakan contoh berikut untuk menambahkan baris JSON ke dataset.

    CLI

    Ganti nilaiGroundTruth dengan Garis JSON yang ingin Anda gunakan. Anda perlu untuk melarikan diri setiap karakter khusus dalam JSON Line.

    aws rekognition update-dataset-entries\ --dataset-arn dataset_arn \ --changes '{"GroundTruth" : "{\"source-ref\":\"s3://your_bucket/your_image\",\"BB\":{\"annotations\":[{\"left\":1776,\"top\":1017,\"width\":458,\"height\":317,\"class_id\":0},{\"left\":1797,\"top\":1334,\"width\":418,\"height\":415,\"class_id\":1},{\"left\":2597,\"top\":1361,\"width\":655,\"height\":329,\"class_id\":2},{\"left\":2581,\"top\":1020,\"width\":689,\"height\":338,\"class_id\":3}],\"image_size\":[{\"width\":4000,\"height\":2667,\"depth\":3}]},\"BB-metadata\":{\"job-name\":\"labeling-job/BB\",\"class-map\":{\"0\":\"comparator\",\"1\":\"pot_resistor\",\"2\":\"ir_phototransistor\",\"3\":\"ir_led\"},\"human-annotated\":\"yes\",\"objects\":[{\"confidence\":1},{\"confidence\":1},{\"confidence\":1},{\"confidence\":1}],\"creation-date\":\"2021-06-22T10:10:48.492Z\",\"type\":\"groundtruth/object-detection\"}}" }' \ --cli-binary-format raw-in-base64-out \ --profile custom-labels-access
    Python

    Gunakan kode berikut. Menyediakan parameter baris perintah berikut:

    • set data - ARN set data yang ingin Anda perbarui.

    • updates_file - file yang berisi pembaruan JSON Line.

    # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 """ Purpose Shows how to add entries to an Amazon Rekognition Custom Labels dataset. """ import argparse import logging import time import json import boto3 from botocore.exceptions import ClientError logger = logging.getLogger(__name__) def update_dataset_entries(rek_client, dataset_arn, updates_file): """ Adds dataset entries to 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 yuo want to update. :param updates_file: The manifest file of JSON Lines that contains the updates. """ try: status="" status_message="" # Update dataset entries. logger.info("Updating dataset %s", dataset_arn) with open(updates_file) as f: manifest_file = f.read() changes=json.loads('{ "GroundTruth" : ' + json.dumps(manifest_file) + '}') rek_client.update_dataset_entries( Changes=changes, DatasetArn=dataset_arn ) finished=False while finished is False: dataset=rek_client.describe_dataset(DatasetArn=dataset_arn) status=dataset['DatasetDescription']['Status'] status_message=dataset['DatasetDescription']['StatusMessage'] if status == "UPDATE_IN_PROGRESS": logger.info("Updating dataset: %s ", dataset_arn) time.sleep(5) continue if status == "UPDATE_COMPLETE": logger.info("Dataset updated: %s : %s : %s", status, status_message, dataset_arn) finished=True continue if status == "UPDATE_FAILED": error_message = f"Dataset update failed: {status} : {status_message} : {dataset_arn}" logger.exception(error_message) raise Exception (error_message) error_message = f"Failed. Unexpected state for dataset update: {status} : {status_message} : {dataset_arn}" logger.exception(error_message) raise Exception(error_message) logger.info("Added entries to dataset") return status, status_message except ClientError as err: logger.exception("Couldn't update dataset: %s", 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 update." ) parser.add_argument( "updates_file", help="The manifest file of JSON Lines that contains the updates." ) 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"Updating dataset {args.dataset_arn} with entries from {args.updates_file}.") # Update the dataset. session = boto3.Session(profile_name='custom-labels-access') rekognition_client = session.client("rekognition") status, status_message=update_dataset_entries(rekognition_client, args.dataset_arn, args.updates_file) print(f"Finished updates dataset: {status} : {status_message}") except ClientError as err: logger.exception("Problem updating dataset: %s", err) print(f"Problem updating dataset: {err}") except Exception as err: logger.exception("Problem updating dataset: %s", err) print(f"Problem updating dataset: {err}") if __name__ == "__main__": main()
    Java V2
    • set data - ARN set data yang ingin Anda perbarui.

    • update_file - file yang berisi pembaruan JSON Line.

    /* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 */ package com.example.rekognition; import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider; import software.amazon.awssdk.core.SdkBytes; import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.rekognition.RekognitionClient; import software.amazon.awssdk.services.rekognition.model.DatasetChanges; import software.amazon.awssdk.services.rekognition.model.DatasetDescription; import software.amazon.awssdk.services.rekognition.model.DatasetStatus; import software.amazon.awssdk.services.rekognition.model.DescribeDatasetRequest; import software.amazon.awssdk.services.rekognition.model.DescribeDatasetResponse; import software.amazon.awssdk.services.rekognition.model.RekognitionException; import software.amazon.awssdk.services.rekognition.model.UpdateDatasetEntriesRequest; import software.amazon.awssdk.services.rekognition.model.UpdateDatasetEntriesResponse; import java.io.FileInputStream; import java.io.InputStream; import java.util.logging.Level; import java.util.logging.Logger; public class UpdateDatasetEntries { public static final Logger logger = Logger.getLogger(UpdateDatasetEntries.class.getName()); public static String updateMyDataset(RekognitionClient rekClient, String datasetArn, String updateFile ) throws Exception, RekognitionException { try { logger.log(Level.INFO, "Updating dataset {0}", new Object[] { datasetArn}); InputStream sourceStream = new FileInputStream(updateFile); SdkBytes sourceBytes = SdkBytes.fromInputStream(sourceStream); DatasetChanges datasetChanges = DatasetChanges.builder() .groundTruth(sourceBytes).build(); UpdateDatasetEntriesRequest updateDatasetEntriesRequest = UpdateDatasetEntriesRequest.builder() .changes(datasetChanges) .datasetArn(datasetArn) .build(); UpdateDatasetEntriesResponse response = rekClient.updateDatasetEntries(updateDatasetEntriesRequest); boolean updated = false; //Wait until update completes do { DescribeDatasetRequest describeDatasetRequest = DescribeDatasetRequest.builder() .datasetArn(datasetArn).build(); DescribeDatasetResponse describeDatasetResponse = rekClient.describeDataset(describeDatasetRequest); DatasetDescription datasetDescription = describeDatasetResponse.datasetDescription(); DatasetStatus status = datasetDescription.status(); logger.log(Level.INFO, " dataset ARN: {0} ", datasetArn); switch (status) { case UPDATE_COMPLETE: logger.log(Level.INFO, "Dataset updated"); updated = true; break; case UPDATE_IN_PROGRESS: Thread.sleep(5000); break; case UPDATE_FAILED: String error = "Dataset update failed: " + datasetDescription.statusAsString() + " " + datasetDescription.statusMessage() + " " + datasetArn; logger.log(Level.SEVERE, error); throw new Exception(error); default: String unexpectedError = "Unexpected update state: " + datasetDescription.statusAsString() + " " + datasetDescription.statusMessage() + " " + datasetArn; logger.log(Level.SEVERE, unexpectedError); throw new Exception(unexpectedError); } } while (updated == false); return datasetArn; } catch (RekognitionException e) { logger.log(Level.SEVERE, "Could not update dataset: {0}", e.getMessage()); throw e; } } public static void main(String args[]) { String updatesFile = null; String datasetArn = null; final String USAGE = "\n" + "Usage: " + "<project_arn> <dataset_arn> <updates_file>\n\n" + "Where:\n" + " dataset_arn - the ARN of the dataset that you want to update.\n\n" + " update_file - The file that includes in JSON Line updates.\n\n"; if (args.length != 2) { System.out.println(USAGE); System.exit(1); } datasetArn = args[0]; updatesFile = args[1]; try { // Get the Rekognition client. RekognitionClient rekClient = RekognitionClient.builder() .credentialsProvider(ProfileCredentialsProvider.create("custom-labels-access")) .region(Region.US_WEST_2) .build(); // Update the dataset datasetArn = updateMyDataset(rekClient, datasetArn, updatesFile); System.out.println(String.format("Dataset updated: %s", datasetArn)); rekClient.close(); } catch (RekognitionException rekError) { logger.log(Level.SEVERE, "Rekognition client error: {0}", rekError.getMessage()); System.exit(1); } catch (Exception rekError) { logger.log(Level.SEVERE, "Error: {0}", rekError.getMessage()); System.exit(1); } } }