{ "cells": [ { "cell_type": "markdown", "id": "cffd59b9", "metadata": {}, "source": [ "# ONNX Runtime + YoloV5s Sample Application\n" ] }, { "cell_type": "markdown", "id": "8a2a3ae2", "metadata": {}, "source": [ "# Prerequisites (DO NOT SKIP)" ] }, { "cell_type": "markdown", "id": "9aaddd01", "metadata": {}, "source": [ "1. In a terminal session on this Jupyter notebook server, run `aws configure`. This allows this notebook server to access Panorama resources and deploy applications on your behalf.\n", "\n", "2. This notebook works best in the Test Utility. Please see [here](https://github.com/aws-samples/aws-panorama-samples/blob/main/docs/EnvironmentSetup.md) to set it up \n", "\n", "3. **VERY IMPORTANT** : This example uses a batch of 8, this means we have to use ATLEAST 2 CAMERAS for this example. Batch size 8 is suitable for Jetson Xavier AGX. And for devices using Jetson Xavier NX module, please select batch size 2 instead of 8. please refer to this [link](https://aws.amazon.com/tw/panorama/appliance/) for more information about your device.\n", "\n", "4. **PLEASE READ THE [README](README.md) INCLUDE WITH THIS BEFORE YOU START USING THIS NOTEBOOK**" ] }, { "cell_type": "markdown", "id": "b1c2f6f8", "metadata": {}, "source": [ "# Set up" ] }, { "cell_type": "markdown", "id": "352b4749", "metadata": {}, "source": [ "Import libraries for use with this notebook environment, you do not need these libraries when you write your application code." ] }, { "cell_type": "code", "execution_count": null, "id": "1183276e", "metadata": {}, "outputs": [], "source": [ "import boto3" ] }, { "cell_type": "markdown", "id": "00f12da5", "metadata": { "tags": [] }, "source": [ "## Notebook parameters\n", "Global constants that help the notebook create Panorama resources on your behalf." ] }, { "cell_type": "code", "execution_count": null, "id": "82721929", "metadata": { "tags": [] }, "outputs": [], "source": [ "# application name\n", "app_name = 'onnx_app'\n", "\n", "## package names and node names\n", "code_package_name = 'onnx_app'\n", "\n", "# AWS account ID\n", "account_id = boto3.client(\"sts\").get_caller_identity()[\"Account\"]" ] }, { "cell_type": "markdown", "id": "d1034c1e", "metadata": {}, "source": [ "## Set up application\n", "\n", "Every application uses the creator's AWS Account ID as the prefix to uniquely identifies the application resources. Running `panorama-cli import-application` replaces the generic account Id with your account Id." ] }, { "cell_type": "code", "execution_count": null, "id": "96ef4328", "metadata": {}, "outputs": [], "source": [ "!cd ./onnx_app && panorama-cli import-application" ] }, { "cell_type": "markdown", "id": "116a5823-1db8-428b-ba70-1217830da841", "metadata": { "tags": [] }, "source": [ "## Build Docker image from Dockerfile" ] }, { "cell_type": "markdown", "id": "79606c88-d0f1-43be-9be7-d78a4f4d0f46", "metadata": {}, "source": [ "Open a terminal, go to ./ONNX_opengpu/dependencies/docker and run\n", "\n", "```sudo docker build -t onnx38:latest . ```" ] }, { "cell_type": "markdown", "id": "337238ff", "metadata": {}, "source": [ "### Build app with container" ] }, { "cell_type": "code", "execution_count": null, "id": "afc63216", "metadata": {}, "outputs": [], "source": [ "container_asset_name = 'onnx_app'" ] }, { "cell_type": "code", "execution_count": null, "id": "25f5b4b1", "metadata": {}, "outputs": [], "source": [ "%%capture captured_output\n", "\n", "# Building container image.This process takes time (5min ~ 10min)\n", "# FIXME : without %%capture, browser tab crashes because of too much output from the command.\n", "\n", "# using local-image\n", "!cd ./onnx_app && panorama-cli build \\\n", " --container-asset-name {container_asset_name} \\\n", " --package-path packages/{account_id}-{code_package_name}-1.0 --local-image" ] }, { "cell_type": "code", "execution_count": null, "id": "81c66f7d-70b6-411c-b86f-5256a47d8516", "metadata": {}, "outputs": [], "source": [ "stdout_lines = captured_output.stdout.splitlines()\n", "stderr_lines = captured_output.stderr.splitlines()\n", "print(\" :\")\n", "print(\" :\")\n", "for line in stdout_lines[-30:] + stderr_lines[-30:]:\n", " print(line)" ] }, { "cell_type": "markdown", "id": "cc520d6b-7505-4e93-851f-2a5821ce1494", "metadata": {}, "source": [ "### Special flags in package.json\n", "\n", "* Step 1 : Before you deploy the application, open ONNX_opengpu/onnx_app/packages/(account-id)-onnx_app-1.0/package.json\n", "* Step 2 : Add the following flags to the package.json\n", "\n", "```\n", "\"requirements\": \n", " [{\n", " \"type\" : \"hardware_access\",\n", " \"inferenceAccelerators\": [ \n", " {\n", " \"deviceType\": \"nvhost_gpu\",\n", " \"sharedResourcePolicy\": {\n", " \"policy\" : \"allow_all\"\n", " }\n", " }\n", " ]\n", " }]\n", "```\n", "\n", "The assets should look something like this\n", "\n", "```\n", "\"assets\": [\n", " {\n", " \"name\": \"onnx_app\",\n", " \"implementations\": [\n", " {\n", " \"type\": \"container\",\n", " \"assetUri\": \"9a49a98784f4571adacc417f00942dac7ef2e34686eef21dca9fcb7f4b7ffd70.tar.gz\",\n", " \"descriptorUri\": \"4bab130ec48eea84e072d9fe813b947e9d9610b2924099036b0165026a91d306.json\",\n", " \"requirements\": \n", " [{\n", " \"type\" : \"hardware_access\",\n", " \"inferenceAccelerators\": [ \n", " {\n", " \"deviceType\": \"nvhost_gpu\",\n", " \"sharedResourcePolicy\": {\n", " \"policy\" : \"allow_all\"\n", " }\n", " }\n", " ]\n", " }]\n", " }\n", " ]\n", " }\n", "],\n", "```" ] }, { "cell_type": "markdown", "id": "f017081e", "metadata": {}, "source": [ "### Upload application to Panorama for deploying to devices" ] }, { "cell_type": "code", "execution_count": null, "id": "e8bc1f3b", "metadata": {}, "outputs": [], "source": [ "# This step takes some time, depending on your network environment.\n", "!cd ./onnx_app && pwd && panorama-cli package-application" ] }, { "cell_type": "markdown", "id": "4a6794d7", "metadata": {}, "source": [ "### Ready for deploying to a device\n", "\n", "Congrats! Your app is now ready to deploy to a device. Next, you can continue in this notebook to deploy the app programmatically or you can go to the Panorama console and deploying using the AWS Console. The console makes it easier to select camera streams and select the devices you want to deploy to. Programmatic deployment is faster to complete and easier to automate." ] }, { "cell_type": "markdown", "id": "e8e572a8", "metadata": {}, "source": [ "# Deploy app to device" ] }, { "cell_type": "markdown", "id": "a501c4a9-be79-4ed3-b9bc-323fca6e2092", "metadata": {}, "source": [ "* Step 1: Copy the contents of./graphs/onnx_app/graph.json\n", "* Step 2 : Go to the AWS Panorama Console, click Deploy Application\n", "* Step 3 : Paste the contents you just copied\n", "* Step 4 : Select the device\n", "* Step 5: Select atleast 2 cameras\n", "* Step 6: Configure the batch size with desired batch size. 8 for Jetson Xavier AGX and 2 for Jetson NX. For more info about your Panorama spec, please refer to this [link](https://aws.amazon.com/tw/panorama/appliance/)\n", "* Step 7 : Deploy\n", "\n", "The deployment should take about 20 minutes" ] }, { "cell_type": "code", "execution_count": null, "id": "b6c637df-7ada-4454-b61d-f2f8b5cbf16d", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.9" } }, "nbformat": 4, "nbformat_minor": 5 }