本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
SageMaker Python SDK 提供一般估算器類別Estimator
類別或 Estimator.fit
方法時指定其中一個資料輸入模式。下列程式碼範本顯示兩種指定輸入模式的方法。
使用估算器類別指定輸入模式
from sagemaker.estimator
import Estimator
from sagemaker.inputs import TrainingInput
estimator = Estimator(
checkpoint_s3_uri='s3://amzn-s3-demo-bucket/checkpoint-destination/
',
output_path='s3://amzn-s3-demo-bucket/output-path/
',
base_job_name='job-name
',
input_mode='File
' # Available options: File | Pipe | FastFile
...
)
# Run the training job
estimator.fit(
inputs=TrainingInput(s3_data="s3://amzn-s3-demo-bucket/my-data/train
")
)
如需更多資訊,請參閱 SageMaker Python SDK 文件內的 sagemaker.estimator.Estimator
透過 estimator.fit()
方法指定輸入模式
from sagemaker.estimator
import Estimator
from sagemaker.inputs import TrainingInput
estimator = Estimator(
checkpoint_s3_uri='s3://amzn-s3-demo-bucket/checkpoint-destination/
',
output_path='s3://amzn-s3-demo-bucket/output-path/
',
base_job_name='job-name
',
...
)
# Run the training job
estimator.fit(
inputs=TrainingInput(
s3_data="s3://amzn-s3-demo-bucket/my-data/train
",
input_mode='File
' # Available options: File | Pipe | FastFile
)
)
如需更多資訊,請參閱 SageMaker Python SDK 文件內的sagemaker.estimator.Estimator.fit
提示
若要進一步了解如何使用 SageMaker Python SDK 估算器搭配 VPC 組態設定 Amazon FSx for Lustre 或 Amazon EFS,請參閱 SageMaker AI Python SDK 文件中的使用檔案系統做為訓練輸入
提示
資料輸入模式與 Amazon S3、Amazon EFS 和 FSx for Lustre 整合,是設定資料來源以獲得最佳實務的最佳建議方式。您可以使用 SageMaker AI 受管儲存選項和輸入模式,以策略方式改善資料載入效能,但沒有嚴格限制。您可以直接在訓練容器中撰寫自己的資料讀取邏輯。例如,您可以設定為從不同的資料來源讀取、撰寫自己的 S3 資料載入器類別,或在訓練指令碼中使用第三方架構的資料載入功能。不過,您必須確定指定 SageMaker AI 可以辨識的正確路徑。
提示
如果您使用自訂訓練容器,請務必安裝 SageMaker 訓練工具組
有關如何使用低階 SageMaker API 設定資料輸入模式的更多相關資訊Amazon SageMaker AI 如何提供訓練資訊,請參閱 ,CreateTrainingJob
API 和 AlgorithmSpecification
內的 TrainingInputMode
。