GithubHelp home page GithubHelp logo

greengrass-v2-sagemaker-edge-manager-python's Introduction

greengrass-v2-sagemaker-edge-manager-python

This code sample demonstrates how to integrate SageMaker Edge Manager with Greengrass v2 via components. At the end of the sample, you will have a Python-based component running inference at the edge with the SageMaker Edge Manager binary agent, and a YOLOv3 Darknet model.

In the folder examples/mlops-console-example there are two additional examples that use SageMaker Edge Manager and Greengrass v2 to implement a machine learning operations flow on NXP or virtual devices. They include step by step implementation instructions from the AWS Console.

AWS CLI setup

Ensure you have AWS CLI installed, a IAM user with an access key, and a named profile configured:

Define key variables

NOTE: In this demo, we are using a NVIDIA Xavier NX / AGX Xavier development kit. Please adjust PLATFORM as required for your device.

Valid PLATFORM options include linux-armv8, linux-x64, windows-x86, and windows-x64.

Valid TARGET_DEVICE options can be found here: Supported edge devices for SageMaker Neo.

export AWS_PROFILE=<PROFILE-NAME>
export AWS_REGION=<REGION>
export PLATFORM=linux-armv8
export TARGET_DEVICE=jetson_xavier
export SSH_USER=<USER>
export SSH_HOST=<IP_ADDRESS>
export IOT_THING_NAME=<THING_NAME>
export BUCKET_NAME=<BUCKET_NAME>

Allow executions of scripts

chmod +x ./scripts/*.sh

Make S3 bucket for your custom components

aws s3 mb s3://$BUCKET_NAME --profile $AWS_PROFILE --region $AWS_REGION

Download/upload Darknet sample model

./scripts/download_upload_sample_model.sh $AWS_PROFILE $BUCKET_NAME

Create SageMaker Execution Role

export SM_ROLE_NAME=smem-role
./scripts/create_sagemaker_role.sh $AWS_PROFILE $SM_ROLE_NAME

Compile model with SageMaker Neo

./scripts/create_neo_compilation_job.sh $AWS_PROFILE $BUCKET_NAME $AWS_REGION $SM_ROLE_NAME $TARGET_DEVICE

Package Neo model in SageMaker Edge Manager

./scripts/package_neo_model.sh $AWS_PROFILE $BUCKET_NAME $AWS_REGION $SM_ROLE_NAME

Download, install, provision, and start Greengrass v2

NOTE: this is done over SSH to avoid installing AWS CLI and credentials directly on the device.

./scripts/install-ggv2-ssh.sh $AWS_PROFILE $SSH_USER $SSH_HOST $AWS_REGION $IOT_THING_NAME

Download SageMaker Edge Manager archive

./scripts/download_edge_manager_package.sh $AWS_PROFILE $PLATFORM    

Add SageMaker Edge Manager agent binary to artifacts

./scripts/add_agent_artifact.sh $AWS_PROFILE $PLATFORM 0.1.0 $AWS_REGION

Compile and add SageMaker Edge Manager Python client stubs to artifacts

pip install grpcio-tools
pip install --upgrade protobuf
./scripts/compile_add_python_stub_artifacts.sh $PLATFORM aws.sagemaker.edgeManagerPythonClient 0.1.0

Create device fleet in SageMaker Edge Manager, and add device to fleet

./scripts/create_device_fleet_register_device.sh $AWS_PROFILE $AWS_REGION $BUCKET_NAME $IOT_THING_NAME

Update recipes

  • In all of the recipe files, replace YOUR_BUCKET_NAME with the value assigned to $BUCKET_NAME

Upload your custom components to S3 bucket

./scripts/upload_component_version.sh $AWS_PROFILE com.model.darknet 0.1.0 $BUCKET_NAME $AWS_REGION
./scripts/upload_component_version.sh $AWS_PROFILE aws.sagemaker.edgeManagerPythonClient 0.1.0 $BUCKET_NAME $AWS_REGION

NOTE: you cannot overwrite an existing component version. To upload a new version, you will need to update the version number in the artifact directory, the recipe file name, and the version numbers in the recipe file. As an alternative, you can also delete a specific component version. For this, use the following command:

./delete_component.sh $AWS_PROFILE <COMPONENT-NAME> <COMPONENT-VERSION> $AWS_REGION

Create/Update your Greengrass v2 deployment

Create a new Greengrass v2 deployment, including the following components:

  • com.model.darknet (v0.1.0)
  • aws.greengrass.SageMakerEdgeManager (>=1.0.2)
  • aws.sagemaker.edgeManagerPythonClient (v0.1.0)

Configure SageMaker Edge Manager public component

Configure the aws.greengrass.SageMakerEdgeManager component, and use the following JSON as the Configuration to merge value. Be sure to update the BucketName attribute.

{
  "CaptureDataPeriodicUpload": "false",
  "CaptureDataPeriodicUploadPeriodSeconds": "8",
  "DeviceFleetName": "ggv2-smem-fleet",
  "BucketName": "<YOUR_BUCKET_NAME>",
  "CaptureDataBase64EmbedLimit": "3072",
  "CaptureDataPushPeriodSeconds": "4",
  "SagemakerEdgeLogVerbose": "false",
  "CaptureDataBatchSize": "10",
  "CaptureDataDestination": "Cloud",
  "FolderPrefix": "sme-capture",
  "UnixSocketName": "/tmp/sagemaker_edge_agent_example.sock",
  "CaptureDataBufferSize": "30"
}

Security

See CONTRIBUTING for more information.

License

This library is licensed under the MIT-0 License. See the LICENSE file.

greengrass-v2-sagemaker-edge-manager-python's People

Contributors

amazon-auto avatar dependabot[bot] avatar dhwalters423 avatar jonslo avatar michaelwalker-git avatar pavankumar2203 avatar tsmiyamoto avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.