훈련을 위한 공통 데이터 형식 - 아마존 SageMaker

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

훈련을 위한 공통 데이터 형식

교육을 준비하려면 Amazon EMR, Amazon Redshift, Amazon Redshift, Amazon Relational Database AWS Service AWS Glue, Amazon Athena를 비롯한 다양한 서비스를 사용하여 데이터를 사전 처리할 수 있습니다. 사전 처리 이후 데이터를 Amazon S3 버킷에 게시합니다. 교육을 위해 데이터는 다음과 같은 일련의 변환 및 변환을 거쳐야 합니다.

  • 훈련 데이터 직렬화(사용자가 처리)

  • 훈련 데이터 역직렬화(알고리즘이 처리)

  • 훈련 모델 직렬화(알고리즘이 처리)

  • 교육 모델 역직렬화(선택 사항, 사용자가 처리)

알고리즘의 교육 SageMaker 부분에서 Amazon을 사용할 때는 모든 데이터를 한 번에 업로드해야 합니다. 해당 위치에 더 많은 데이터가 추가된 경우 새로운 훈련 호출을 통해 새 모델을 생성해야 합니다.

기본 제공 알고리즘으로 지원되는 콘텐츠 유형

다음 테이블에는 일반적으로 지원되는 몇 가지 ContentType 값과 이를 사용하는 알고리즘이 나와 있습니다.

ContentTypes 내장 알고리즘용
ContentType 알고리즘
application/x-image 객체 감지 알고리즘, 의미 체계 분할
application/x-recordio

Object Detection 알고리즘

application/x-recordio-protobuf

Factorization Machines, K-Means, k-NN, Latent Dirichlet Allocation, Linear Learner, NTM, PCA, RCF, Sequence-to-Sequence

application/jsonlines

BlazingText, Deepar

이미지/jpeg

객체 감지 알고리즘, 의미 체계 분할

이미지/png

객체 감지 알고리즘, 의미 체계 분할

text/csv

IP Insights, K-Means, k-NN, Latent Dirichlet Allocation, Linear Learner, NTM, PCA, RCF, XGBoost

텍스트/libsvm

XGBoost

각 알고리즘에서 사용되는 파라미터에 대한 요약은 개별 알고리즘의 설명서 또는 이 테이블을 참조하세요.

파이프 모드 사용

파이프 모드에서는 Amazon Simple Storage Service(S3)에서 훈련 작업이 데이터를 직접 스트리밍합니다. 스트리밍을 통해 훈련 작업의 시작 시간을 더 앞당기고 처리량을 늘릴 수 있습니다. 이는 Amazon S3의 데이터가 훈련 인스턴스 볼륨에 저장되는 파일 모드와는 대조적입니다. 파일 모드에서는 최종 모델 결과물과 전체 훈련 데이터 세트를 저장하기 위한 공간을 사용합니다. 파이프 모드에서 Amazon S3에서 직접 데이터를 스트리밍하면 훈련 인스턴스의 Amazon Elastic 블록 스토어 볼륨 크기를 줄일 수 있습니다. 파이프 모드에서는 최종 모델 결과물을 저장하는 데 충분한 디스크 공간만 필요합니다. 훈련 입력 모드에 대한 자세한 정보는 AlgorithmSpecification 단원을 참조하세요.

CSV 형식 사용

많은 Amazon SageMaker 알고리즘은 CSV 형식의 데이터를 사용한 교육을 지원합니다. CSV 형식의 데이터를 훈련에 사용하려면 입력 데이터 채널 사양에서 text/csvContentType으로 지정하세요. SageMaker Amazon에서는 CSV 파일에 헤더 레코드가 없고 대상 변수가 첫 번째 열에 있어야 한다고 요구합니다. 목표가 없는 비지도 학습 알고리즘을 실행하려면 콘텐츠 유형에서 레이블 열의 수를 지정합니다. 예를 들어, 이 경우에는 'content_type=text/csv;label_size=0'입니다. 자세한 내용은 이제 Amazon SageMaker 내장 알고리즘에서 더 빠르게 학습할 수 있도록 CSV 데이터 세트와 함께 파이프 모드 사용을 참조하십시오.

RecordIO 형식 사용

protobuf Recordio 형식에서 데이터셋의 각 관측값을 4바이트 부동 SageMaker 소수점 집합의 이진 표현으로 변환한 다음 protobuf values 필드에 로드합니다. 데이터 준비에 Python을 사용하는 경우에는 기존 변환을 사용하는 것이 좋습니다. 하지만 다른 언어를 사용하는 경우 아래 protobuf 정의 파일은 데이터를 protobuf 형식으로 변환하는 데 사용하는 스키마를 제공합니다. SageMaker

참고

일반적으로 사용되는 numPy 배열을 protobuf recordIO 형식으로 변환하는 방법을 보여주는 예제는 An Introduction to Factorization Machines with 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; }

프로토콜 버퍼를 생성한 후 Amazon이 액세스할 SageMaker 수 있고 프로토콜의 InputDataConfig 일부로 전달될 수 있는 Amazon S3 위치에 저장합니다create_training_job.

참고

모든 Amazon SageMaker 알고리즘의 ChannelName 경우 in을 로 InputDataConfig 설정해야 합니다train. 일부 알고리즘은 또한 검증 또는 테스트 input channels을 지원합니다. 이러한 채널은 일반적으로 홀드아웃 데이터 세트를 사용하여 모델의 성능을 평가하는 데 사용됩니다. 홀드아웃 데이터 세트는 초기 훈련에서는 사용되지 않지만 추가로 모델을 튜닝하는 데에는 사용할 수 있습니다.

교육된 모델 역직렬화

Amazon SageMaker 모델은 create_training_job 호출의 OutputDataConfig S3OutputPath 파라미터에 지정된 S3 버킷에 model.tar.gz 형식으로 저장됩니다. S3 버킷은 노트북 인스턴스와 동일한 AWS 지역에 있어야 합니다. 호스팅 모델 생성 시 이러한 모델 결과물 대부분을 지정할 수 있습니다. 또한 노트북 인스턴스에서 이를 열고 검토할 수 있습니다. model.tar.gz가 압축 해제될 때 직렬화된 Apache MXNet 객체인 model_algo-1이 포함됩니다. 예를 들어 다음을 사용하여 메모리에 k-means 모델을 로드하고 이를 검토할 수 있습니다.

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