概要

TODO:

基本的に、以下のチュートリアルを参考に実施する。
https://aws.amazon.com/jp/getting-started/tutorials/build-train-deploy-machine-learning-model-sagemaker/
https://docs.aws.amazon.com/ja_jp/sagemaker/latest/dg/pytorch.html
https://sagemaker.readthedocs.io/en/stable/using_pytorch.html

目次

notebook instance の作成

Amazon SageMaker コンソールから ノートブックインスタンス に移動後、[ノートブックインスタンスの作成] を押下して作成する。

今回は以下の通り作成した。
※以下に記載のないものは、全て未選択 または デフォルト値で作成した。

設定名設定内容補足
ノートブックインスタンス名sample-notebook1
ノートブックインスタンスのタイプml.t2.medium
Elastic Inference今回は使用しない推論をガンガン行う場合は使用する(GPUが使える)
ライフサイクル設定なし
ボリュームサイズ5GB
IAM ロール[新しいロールの作成] から 作成「任意の S3 バケット」へのアクセスを許可。
ルートアクセス有効化

しばらくするとステータスが [Pending] から [InService] に変わるので、しばらく待つ。

データの準備

[Jupyter を開く] から jupyter notebook を開く。

モデルのトレーニング

TODO:

モデルのデプロイ

TODO:

モデルの性能評価

TODO:

後片付け

TODO:
import torch
import os

def model_fn(model_dir):
    model = Your_Model()
    with open(os.path.join(model_dir, 'model.pth'), 'rb') as f:
        model.load_state_dict(torch.load(f))
    return model
# Deserialize the Invoke request body into an object we can perform prediction on
input_object = input_fn(request_body, request_content_type)

# Perform prediction on the deserialized object, with the loaded model
prediction = predict_fn(input_object, model)

# Serialize the prediction result into the desired response content type
output = output_fn(prediction, response_content_type)
import boto3
client = boto3.client('sagemaker-runtime')
 
response = client.invoke_endpoint(
    EndpointName='<your-endpoint-name>',
    Body=b'5.1,3.5,1.4,0.2',
    ContentType='text/csv',
    Accept='application/json'
)
aws sagemaker invoke-endpoint --endpoint-name dog-face-endpoint-1 --body file://test.jpeg --content-type image/jpeg outfile out.json

エンドポイントでの処理の流れ

# Deserialize the Invoke request body into an object we can perform prediction on
input_object = input_fn(request_body, request_content_type)

# Perform prediction on the deserialized object, with the loaded model
prediction = predict_fn(input_object, model)

# Serialize the prediction result into the desired response content type
output = output_fn(prediction, response_content_type)

トップ   一覧 単語検索 最終更新   ヘルプ   最終更新のRSS