

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

# リアルタイム推論用の Autopilot モデルをデプロイする
<a name="text-classification-deploy-models"></a>

Amazon SageMaker Autopilot モデルをトレーニングした後、エンドポイントを設定してインタラクティブに予測を取得できます。このセクションでは、モデルから予測を取得するために、SageMaker AI リアルタイム推論エンドポイントにモデルをデプロイする手順について説明します。

## リアルタイム推論
<a name="autopilot-deploy-models-text-image-classification-realtime"></a>

リアルタイム推論は、リアルタイム、インタラクティブ、低レイテンシーの要件がある推論ワークロードに最適です。このセクションでは、リアルタイム推論を使用してモデルからインタラクティブに予測を取得する方法を説明します。

SageMaker API を使用して、Autopilot 実験で最適な検証メトリクスを生成したモデルを、次のように手動でデプロイできます。

あるいは、Autopilot テストの作成時に自動デプロイオプションを選択することもできます。モデルの自動デプロイの設定方法については、`[CreateAutoMLJobV2](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateAutoMLJobV2.html#API_CreateAutoMLJobV2_RequestParameters)` のリクエストパラメータの「`[ModelDeployConfig](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateAutoMLJobV2.html#sagemaker-CreateAutoMLJobV2-request-ModelDeployConfig)`」を参照してください。これにより、エンドポイントが自動的に作成されます。

**注記**  
不要な料金が発生しないようにするには、作成された不要なエンドポイントとリソースをモデルデプロイから削除します。リージョンごとのインスタンスの料金の詳細については、[「Amazon SageMaker の料金」](https://aws.amazon.com/sagemaker/pricing/)を参照してください。

1. **候補となるコンテナ定義を取得する**

   [InferenceContainers](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_AutoMLCandidate.html#sagemaker-Type-AutoMLCandidate-InferenceContainers) から候補コンテナ定義を取得します。推論用のコンテナ定義とは、トレーニング済みの SageMaker AI モデルをデプロイして実行し、予測を行うために設計されたコンテナ化された環境を指します。

   次の AWS CLI コマンド例では、[DescribeAutoMLJobV2](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_DescribeAutoMLJobV2.html) API を使用して、最適なモデル候補の候補定義を取得します。

   ```
   aws sagemaker describe-auto-ml-job-v2 --auto-ml-job-name job-name --region region
   ```

1. **候補の一覧表示**

   次の AWS CLI コマンド例では、[ListCandidatesForAutoMLJob](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_ListCandidatesForAutoMLJob.html) API を使用してすべてのモデル候補を一覧表示します。

   ```
   aws sagemaker list-candidates-for-auto-ml-job --auto-ml-job-name <job-name> --region <region>
   ```

1. **SageMaker AI モデルを作成する**

   前のステップのコンテナ定義と任意の候補を使用し、[CreateModel](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateModel.html) API を使用して SageMaker AI モデルを作成します。例として、次の AWS CLI コマンドを参照してください。

   ```
   aws sagemaker create-model --model-name '<your-candidate-name>' \
                       --containers ['<container-definition1>, <container-definition2>, <container-definition3>]' \
                       --execution-role-arn '<execution-role-arn>' --region '<region>
   ```

1. **エンドポイント設定の作成**

   次の AWS CLI コマンド例では、[CreateEndpointConfig](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateEndpointConfig.html) API を使用してエンドポイント設定を作成します。

   ```
   aws sagemaker create-endpoint-config --endpoint-config-name '<your-endpoint-config-name>' \
                       --production-variants '<list-of-production-variants>' \
                       --region '<region>'
   ```

1. **エンドポイントの作成** 

   次の AWS CLI 例では、[CreateEndpoint](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateEndpoint.html) API を使用してエンドポイントを作成します。

   ```
   aws sagemaker create-endpoint --endpoint-name '<your-endpoint-name>' \
                       --endpoint-config-name '<endpoint-config-name-you-just-created>' \
                       --region '<region>'
   ```

   [DescribeEndpoint](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_DescribeEndpoint.html) API を使用して、エンドポイントのデプロイの進行状況を確認します。例として、次の AWS CLI コマンドを参照してください。

   ```
   aws sagemaker describe-endpoint —endpoint-name '<endpoint-name>' —region <region>
   ```

   `EndpointStatus` が `InService` に変更されると、エンドポイントはリアルタイム推論に使用できるようになります。

1. **エンドポイントの呼び出し** 

   以下のコマンド構造は、エンドポイントを呼び出してリアルタイム推論を行います。

   ```
   aws sagemaker invoke-endpoint --endpoint-name '<endpoint-name>' \ 
                     --region '<region>' --body '<your-data>' [--content-type] '<content-type>' <outfile>
   ```