TensorFlow 框架處理器 - Amazon SageMaker

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

TensorFlow 框架處理器

TensorFlow 是一個開源的機器學習和人工智能庫。Amazon SageMaker Python 開發套件TensorFlowProcessor中的功能可讓您使用 TensorFlow 指令碼執行處理任務。當您使用時TensorFlowProcessor,您可以利用 Amazon 建置的 Docker 容器與受管理 TensorFlow 環境,這樣您就不需要攜帶自己的容器。

下列程式碼範例會示範如何使用提供及維護的 Docker 映像TensorFlowProcessor來執行處理工作。 SageMaker請注意,當您執行工作時,您可以在source_dir引數中指定一個包含指令碼和相依性的目錄,而且您可以在source_dir目錄中有一個requirements.txt檔案,指定處理指令碼的相依性。 SageMaker 處理會在容器requirements.txt中為您安裝相依性。

from sagemaker.tensorflow import TensorFlowProcessor from sagemaker.processing import ProcessingInput, ProcessingOutput from sagemaker import get_execution_role #Initialize the TensorFlowProcessor tp = TensorFlowProcessor( framework_version='2.3', role=get_execution_role(), instance_type='ml.m5.xlarge', instance_count=1, base_job_name='frameworkprocessor-TF', py_version='py37' ) #Run the processing job tp.run( code='processing-script.py', source_dir='scripts', inputs=[ ProcessingInput( input_name='data', source=f's3://{BUCKET}/{S3_INPUT_PATH}', destination='/opt/ml/processing/input/data' ), ProcessingInput( input_name='model', source=f's3://{BUCKET}/{S3_PATH_TO_MODEL}', destination='/opt/ml/processing/input/model' ) ], outputs=[ ProcessingOutput( output_name='predictions', source='/opt/ml/processing/output', destination=f's3://{BUCKET}/{S3_OUTPUT_PATH}' ) ] )

如果您有一個 requirements.txt 檔案,該檔案應該會是您要在容器中安裝的程式庫清單。source_dir 的路徑可以是相對路徑、絕對路徑或 Amazon S3 URI 路徑。不過,如果您使用 Amazon S3 URI,那麼它必須指向一個 tar.gz 檔案。您可以在為 source_dir 指定的目錄中擁有多個指令碼。若要進一步了解TensorFlowProcessor類別,請參閱 Amazon SageMaker Python 開發套TensorFlow 件中的估算工具。