Greengrass is an open source Internet of Things (IoT) edge runtime and cloud service that helps you build, deploy and manage IoT applications on your devices. *1 IUUQTEPDTBXTBNB[PODPNHSFFOHSBTTWEFWFMPQFSHVJEFXIBUJTJPUHSFFOHSBTTIUNM IUUQTEPDTBXTBNB[PODPNHSFFOHSBTTWEFWFMPQFSHVJEFIPXJUXPSLTIUNM IUUQTBXTBNB[PODPNKQBCPVUBXTXIBUTOFXBXTJPUHSFFOHSBTTTVQQPSUXJOEPXTEFWJDFT 構成イメージ *2 • サポートされる OS は、Windows *3, Linux (Ubuntu, Raspberry Pi OS など) • サポートされる CPU は x86, ARM • Lambda Function を実⾏可能 • DLR (Deep Learning Runtime) を利⽤し たエッジAI推論が可能 • DLR は SageMaker Neo だけではなく、 TVM (Apache の DL Compiler Framework) でコンパイルしたモデルを ロードすることも可能
Train model Evaluate model Deploy to production Monitor SageMaker Studio (IDE) SageMaker Projects (CI/CD) SageMaker Model Building Pipelines (CI/CD) SageMaker Studio Notebooks (Jupyter Notebook) SageMaker Notebook Instances (Jupyter Notebook) SageMaker ML Lineage Tracking (Collecting Information) SageMaker Data Wrangler (Feature of SageMaker Studio) SageMaker Processing (SDK) SageMaker Debugger SageMaker Experiments SageMaker Edge Manager
Train model Evaluate model Deploy to production Monitor SageMaker Clarify (Improving Models) Amazon Augmented AI (Workflow for Human Reviews) SageMaker Ground Truth (Labeling) SageMaker Ground Truth Plus (Labeling) SageMaker Feature Store SageMaker Training Compiler SageMaker Autopilot (Auto ML) SageMaker Canvas (Auto ML) SageMaker Hosting Services SageMaker Serverless Endpoints (Preview) SageMaker Elastic Inference SageMaker Inference Recommender SageMaker Model Registry SageMaker Neo (Compile) SageMaker Model Monitor
is a capability of Amazon SageMaker that enables machine learning models to train once and run anywhere in the cloud and at the edge. *1 Amazon SageMaker Neo を使⽤すると、デベロッパーは、クラウド内の SageMaker とエッジでサポー トされているデバイスで推論するために機械学習 (ML) モデルを最適化できます。 *2 SageMaker Neo は、シングルクリックでトレーニングされたモデルを最適化し、実⾏可能ファイルにコン パイルします。コンパイラは、機械学習モデルを使⽤して、クラウドインスタンスまたはエッジデバイス上の モデルの可能な限り最⾼のパフォーマンスを引き出すパフォーマンス最適化を適⽤します。 *2 IUUQTEPDTBXTBNB[PODPNTBHFNBLFSMBUFTUEHOFPIUNM IUUQTBXTBNB[PODPNKQTBHFNBLFSOFP
Amazon SageMaker Edge Manager provides model management for edge devices so you can optimize, secure, monitor, and maintain machine learning models on fleets of edge devices such as smart cameras, robots, personal computers, and mobile devices. *1 エッジにある機械学習モデルを管理・監視できます。(今回のサンプルでは監視はしません) IUUQTEPDTBXTBNB[PODPNTBHFNBLFSMBUFTUEHFEHFIUNM
にアップロードしましたので、あわせてご参照ください。 https://github.com/iwstkhr/aws-iot-greengrass-edge-inference-sample 1. 事前準備 a. AWS リソース準備 b. 訓練スクリプト作成 c. 推論スクリプト作成 2. SageMaker a. SageMaker 訓練 b. SageMaker Neo コンパイル c. SageMaker Edge Manager パッケージング 3. Greengrass a. Greengrass Core セットアップ b. Greengrass Component 登録 (推論⽤) c. Greengrass Component デプロイ 4. エッジAI推論動作確認
User greengrass-core-setup-user Greengrass Core セットアップ⽤ IAM Role sagemaker-execution-role SageMaker 実⾏ロール IAM Role GreengrassV2TokenExchangeRole Greengrass Core ⽤ロール S3 sagemaker-ml-model-artifacts-{account_id}-{region} ML Model 配置⽤ 事前に以下のAWSリソースを準備しておきます。 各リソースの詳細は、GitHub の CloudFormation Template を参照してください。 % aws cloudformation deploy --template-file ./cfn.yaml --stack-name greengrass-sample --capabilities CAPABILITY_NAMED_IAM Waiting for changeset to be created.. Waiting for stack create/update to complete Successfully created/updated stack - greengrass-sample
-> None: suffix = datetime.now().strftime('%Y-%m-%d_%H-%M-%S') path = os.path.join(path, f'model-{suffix}.pt') # If you use `model.state_dict()`, SageMaker compilation will fail. torch.save(model, path) def parse_args() -> argparse.Namespace: parser = argparse.ArgumentParser() # hyperparameters sent by the client are passed as command-line arguments to the script. # input data and model directories parser.add_argument('--model_dir', type=str) parser.add_argument('--sm_model_dir', type=str, default=os.environ.get('SM_MODEL_DIR')) parser.add_argument('--train', type=str, default=os.environ.get('SM_CHANNEL_TRAIN')) parser.add_argument('--test', type=str, default=os.environ.get('SM_CHANNEL_TEST')) args, _ = parser.parse_known_args() return args training.py
json import os import time import numpy as np from dlr import DLRModel def load_model() -> DLRModel: return DLRModel('/greengrass/v2/work/vgg16-component') inference.py
model.tar.gz の S3 URI データ⼊⼒設定 モデルの Input Shape *1 機械学習フレームワーク 今回は PyTorch フレームワークバージョン 1.8 *1) 訓練済みモデルの仕様は、公式ページを参照してくださ い。 All pre-trained models expect input images normalized in the same way, i.e. mini-batches of 3-channel RGB images of shape (3 x H x W), where H and W are expected to be at least 224. ⼊⼒設定