Format Data Umum untuk Pelatihan - Amazon SageMaker

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

Format Data Umum untuk Pelatihan

Untuk mempersiapkan pelatihan, Anda dapat memproses data Anda menggunakan berbagai AWS layanan, termasuk Amazon EMR, Amazon Redshift AWS Glue, Amazon Relational Database Service, dan Amazon Athena. Setelah preprocessing, publikasikan data ke bucket Amazon S3. Untuk pelatihan, data harus melalui serangkaian konversi dan transformasi, termasuk:

  • Serialisasi data pelatihan (ditangani oleh Anda)

  • Deserialisasi data pelatihan (ditangani oleh algoritme)

  • Serialisasi model pelatihan (ditangani oleh algoritma)

  • Deserialisasi model terlatih (opsional, ditangani oleh Anda)

Saat menggunakan Amazon SageMaker di bagian pelatihan algoritme, pastikan untuk mengunggah semua data sekaligus. Jika lebih banyak data ditambahkan ke lokasi itu, panggilan pelatihan baru perlu dibuat untuk membangun model baru.

Jenis Konten yang Didukung oleh Algoritma Bawaan

Tabel berikut mencantumkan beberapa ContentTypenilai yang didukung umum dan algoritma yang menggunakannya:

ContentTypes untuk Algoritma Bawaan
ContentType Algoritme
aplikasi/x-image Algoritma Deteksi Objek, Segmentasi Semantik
aplikasi/x-recordio

Algoritma Deteksi Objek

aplikasi/x-recordio-protobuf

Mesin Faktorisasi, K-Means, K-NN, Alokasi Dirichlet Laten, Linear Learner, NTM, PCA, RCF, Urutan-ke-Urutan

aplikasi/jsonlines

BlazingText, DeepAR

gambar/jpeg

Algoritma Deteksi Objek, Segmentasi Semantik

gambar/png

Algoritma Deteksi Objek, Segmentasi Semantik

teks/csv

Wawasan IP, K-Means, K-NN, Alokasi Dirichlet Laten, Pelajar Linear, NTM, PCA, RCF, XGBoost

teks/libsvm

XGBoost

Untuk ringkasan parameter yang digunakan oleh setiap algoritma, lihat dokumentasi untuk algoritma individu atau tabel ini.

Menggunakan Mode Pipa

Dalam mode Pipe, pekerjaan latihan Anda mengalirkan data langsung dari Amazon Simple Storage Service (Amazon S3). Streaming dapat memberikan waktu mulai yang lebih cepat untuk pekerjaan pelatihan dan throughput yang lebih baik. Ini berbeda dengan mode File, di mana data Anda dari Amazon S3 disimpan pada volume instans pelatihan. Mode file menggunakan ruang disk untuk menyimpan artefak model akhir dan kumpulan data pelatihan lengkap Anda. Dengan streaming data Anda langsung dari Amazon S3 dalam mode Pipa, Anda mengurangi ukuran volume Amazon Elastic Block Store dari instans pelatihan Anda. Mode pipa hanya membutuhkan ruang disk yang cukup untuk menyimpan artefak model akhir Anda. Lihat AlgorithmSpecificationuntuk detail tambahan tentang mode input pelatihan.

Menggunakan Format CSV

Banyak SageMaker algoritma Amazon mendukung pelatihan dengan data dalam format CSV. Untuk menggunakan data dalam format CSV untuk pelatihan, dalam spesifikasi saluran data input, tentukan text/csv sebagai. ContentType Amazon SageMaker mengharuskan file CSV tidak memiliki catatan header dan variabel target ada di kolom pertama. Untuk menjalankan algoritme pembelajaran tanpa pengawasan yang tidak memiliki target, tentukan jumlah kolom label dalam jenis konten. Misalnya, dalam hal ini'content_type=text/csv;label_size=0'. Untuk informasi selengkapnya, lihat Sekarang menggunakan mode Pipa dengan kumpulan data CSV untuk pelatihan lebih cepat tentang algoritme bawaan Amazon SageMaker.

Menggunakan Format RecorDio

Dalam format protobuf Recordio, SageMaker mengubah setiap pengamatan dalam dataset menjadi representasi biner sebagai satu set float 4-byte, lalu memuatnya di bidang nilai protobuf. Jika Anda menggunakan Python untuk persiapan data Anda, kami sangat menyarankan Anda menggunakan transformasi yang ada ini. Namun, jika Anda menggunakan bahasa lain, file definisi protobuf di bawah ini menyediakan skema yang Anda gunakan untuk mengonversi data Anda ke format protobuf. SageMaker

catatan

Untuk contoh yang menunjukkan cara mengonversi array NumPy yang umum digunakan ke dalam format protobuf RecorDio, lihat Pengantar Mesin Faktorisasi dengan MNIST.

syntax = "proto2"; package aialgs.data; option java_package = "com.amazonaws.aialgorithms.proto"; option java_outer_classname = "RecordProtos"; // A sparse or dense rank-R tensor that stores data as doubles (float64). message Float32Tensor { // Each value in the vector. If keys is empty, this is treated as a // dense vector. repeated float values = 1 [packed = true]; // If key is not empty, the vector is treated as sparse, with // each key specifying the location of the value in the sparse vector. repeated uint64 keys = 2 [packed = true]; // An optional shape that allows the vector to represent a matrix. // For example, if shape = [ 10, 20 ], floor(keys[i] / 20) gives the row, // and keys[i] % 20 gives the column. // This also supports n-dimensonal tensors. // Note: If the tensor is sparse, you must specify this value. repeated uint64 shape = 3 [packed = true]; } // A sparse or dense rank-R tensor that stores data as doubles (float64). message Float64Tensor { // Each value in the vector. If keys is empty, this is treated as a // dense vector. repeated double values = 1 [packed = true]; // If this is not empty, the vector is treated as sparse, with // each key specifying the location of the value in the sparse vector. repeated uint64 keys = 2 [packed = true]; // An optional shape that allows the vector to represent a matrix. // For example, if shape = [ 10, 20 ], floor(keys[i] / 10) gives the row, // and keys[i] % 20 gives the column. // This also supports n-dimensonal tensors. // Note: If the tensor is sparse, you must specify this value. repeated uint64 shape = 3 [packed = true]; } // A sparse or dense rank-R tensor that stores data as 32-bit ints (int32). message Int32Tensor { // Each value in the vector. If keys is empty, this is treated as a // dense vector. repeated int32 values = 1 [packed = true]; // If this is not empty, the vector is treated as sparse with // each key specifying the location of the value in the sparse vector. repeated uint64 keys = 2 [packed = true]; // An optional shape that allows the vector to represent a matrix. // For Exmple, if shape = [ 10, 20 ], floor(keys[i] / 10) gives the row, // and keys[i] % 20 gives the column. // This also supports n-dimensonal tensors. // Note: If the tensor is sparse, you must specify this value. repeated uint64 shape = 3 [packed = true]; } // Support for storing binary data for parsing in other ways (such as JPEG/etc). // This is an example of another type of value and may not immediately be supported. message Bytes { repeated bytes value = 1; // If the content type of the data is known, stores it. // This allows for the possibility of using decoders for common formats // in the future. optional string content_type = 2; } message Value { oneof value { // The numbering assumes the possible use of: // - float16, float128 // - int8, int16, int32 Float32Tensor float32_tensor = 2; Float64Tensor float64_tensor = 3; Int32Tensor int32_tensor = 7; Bytes bytes = 9; } } message Record { // Map from the name of the feature to the value. // // For vectors and libsvm-like datasets, // a single feature with the name `values` // should be specified. map<string, Value> features = 1; // An optional set of labels for this record. // Similar to the features field above, the key used for // generic scalar / vector labels should be 'values'. map<string, Value> label = 2; // A unique identifier for this record in the dataset. // // Whilst not necessary, this allows better // debugging where there are data issues. // // This is not used by the algorithm directly. optional string uid = 3; // Textual metadata describing the record. // // This may include JSON-serialized information // about the source of the record. // // This is not used by the algorithm directly. optional string metadata = 4; // An optional serialized JSON object that allows per-record // hyper-parameters/configuration/other information to be set. // // The meaning/interpretation of this field is defined by // the algorithm author and may not be supported. // // This is used to pass additional inference configuration // when batch inference is used (e.g. types of scores to return). optional string configuration = 5; }

Setelah membuat buffer protokol, simpan di lokasi Amazon S3 yang dapat diakses SageMaker Amazon dan yang dapat diteruskan sebagai bagian dari InputDataConfig in. create_training_job

catatan

Untuk semua SageMaker algoritma Amazon, ChannelName in InputDataConfig harus diatur ketrain. Beberapa algoritma juga mendukung validasi atau pengujian. input channels Ini biasanya digunakan untuk mengevaluasi kinerja model dengan menggunakan dataset penahanan. Kumpulan data penahanan tidak digunakan dalam pelatihan awal tetapi dapat digunakan untuk menyetel model lebih lanjut.

Deserialisasi Model Terlatih

SageMaker Model Amazon disimpan sebagai model.tar.gz di bucket S3 yang ditentukan dalam OutputDataConfig S3OutputPath parameter create_training_job panggilan. Bucket S3 harus berada di AWS Region yang sama dengan instance notebook. Anda dapat menentukan sebagian besar artefak model ini saat membuat model hosting. Anda juga dapat membuka dan meninjaunya di instance notebook Anda. Ketika model.tar.gz untarred, itu berisimodel_algo-1, yang merupakan objek Apache MXNet serial. Misalnya, Anda menggunakan yang berikut ini untuk memuat model k-means ke dalam memori dan melihatnya:

import mxnet as mx print(mx.ndarray.load('model_algo-1'))