Skip to content

aws-samples/greengrass-v2-sagemaker-edge-manager-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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.

About

No description or website provided.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published