TensorFlow 框架处理器 - 亚马逊 SageMaker AI
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

TensorFlow 框架处理器

TensorFlow 是一个开源机器学习和人工智能库。Amazon SageMaker Python SDK 中的 TensorFlowProcessor 为您提供了使用 TensorFlow 脚本运行处理作业的功能。在使用 TensorFlowProcessor 时,您可以利用 Amazon 构建的 Docker 容器和托管的 TensorFlow 环境,这样您便无需自带容器。

以下代码示例显示了如何使用 TensorFlowProcessor 以及 SageMaker AI 提供并维护的 Docker 映像运行处理作业。请注意,在运行作业时,您可以在 source_dir 参数中指定包含脚本和依赖关系的目录,并且可以在 source_dir 目录中有一个 requirements.txt 文件以指定处理脚本的依赖项。SageMaker Processing 会在容器的 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 SDK》中的 TensorFlow 估算器