

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# TensorFlow フレームワークプロセッサ
<a name="processing-job-frameworks-tensorflow"></a>

TensorFlow は、オープンソースの機械学習と人工知能のライブラリです。Amazon SageMaker Python SDK の `TensorFlowProcessor` は、TensorFlow スクリプトを使用して処理ジョブを実行する機能を提供します。`TensorFlowProcessor` を使用すると、Amazon が構築した Docker コンテナと TensorFlow のマネージド環境を活用できるため、独自のコンテナを持ち込む必要がなくなります。

次のサンプルは、`TensorFlowProcessor` を使用して、SageMaker AI が提供し、管理する Docker イメージを使った Processing ジョブを実行する方法を示しています。ジョブを実行するとき、`source_dir` 引数にスクリプトと依存関係を含むディレクトリを指定でき、処理スクリプトの依存関係を指定する `requirements.txt` ファイルを `source_dir` ディレクトリ内に置くことができることにご注意ください。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 Estimator](https://sagemaker.readthedocs.io/en/stable/frameworks/tensorflow/sagemaker.tensorflow.html#tensorflow-estimator)」を参照してください。