Loading repository data…
Loading repository data…
michhar / repository
Here resides an end-to-end sample of using an NVIDIA Jetson platform as an Azure IoT Edge device with Live Video Analytics Edge and Azure Blob Storage. An open-source ML model is utilized to detect objects in an RSTP stream simulator. A Python web app is included for reviewing AI detections from Blob Storage.
A transparent discovery signal based on current public GitHub metadata.
This score does not audit code, security, maintainers, documentation quality, or suitability. Verify the repository and its current documentation before adoption.
This repo is an example of running an AI container on the Jetson platform in conjunction with the Azure Blob Storage IoT Edge module using the Live Video Analytics as a platform ontop of Azure IoT Edge runtime.
The purpose of this architecture is to create a pipeline that can route video (frame-by-frame) into an AI module for inferencing on the edge (image classification, object detection, etc.) that, in turn, stores output frames in a Blob Storage IoT Edge module storage container (a storage container, here, is a unit of storage within the Blob Edge module). The Blob Storage IoT storage container or set of containers essentially replicate to the Azure cloud (using some tunable user settings), to Azure Blob Storage, given internet connectivity (or stores on the edge until connectivity is achieved).
In the diagram below, frames from an AI module are shown being sent on the edge to two storage containers in the Blob Edge module: 1) for highly confident detection frames and 2) for the more poorly scoring detections (an indication that objects might not be being detected well by the ML model). Poorly performing frames from the AI edge module are good candidates for labeling and retraining the vision ML model to boost performance, thus have their own container, "unannotaed". Once the frames are replicated in the cloud in Azure Blob Storage, Azure Machine Learning may be used to label and retrain the ML model. The confident, annotated frames in the "annotated" conatiner could be reviewed, for instance, within an Azure Web App. Code provided in this repository.
This AI module (docker container) utilizes the GPU on the Jetson (with NVIDIA drivers, CUDA and cuDNN installed) using an NVIDIA L4T (linux for Tegra) base image with TensorFlow 2 installed. The Jetson must have been flashed with Jetpack 4.4.
nvidia-docker)sudo with dockerCreate the following resources:
Note: All of these resources should be created in the same resource group to make it easier to clean-up later. Also, all of these resources may be create in the Portal or with the Azure CLI on the command line.
The following instructions will enable you to build a docker container with a YOLOv4 (tiny) TensorFlow Lite model using nginx, gunicorn, flask, and runit. The app code is based on the tensorflow-yolov4-tflite project. This project uses TensorFlow v2.
Note: References to third-party software in this repo are for informational and convenience purposes only. Microsoft does not endorse nor provide rights for the third-party software. For more information on third-party software please see the links provided above.
scripts/generate_key_for_local.py or a tool like GeneratePlus.app/ folder called .env with the following contents:LOCAL_STORAGE_ACCOUNT_NAME=<Name for local blob storage in IoT edge Blob Storage module (default: annotatedimageslocal)>
LOCAL_STORAGE_ACCOUNT_KEY=<Key you generated for local IoT edge Blob Storage module in double quotes>
Note:
annotated-images-yolo4lowconf-images-yolo4sudo nvidia-docker build . -t <your ACR URL>/tiny-yolov4-tflite:arm64v8-cuda-cudnn -f arm64v8-gpu-cudnn.dockerfile
Log in to ACR with the Azure CLI (also may use docker login):
az acr login --name <name of your ACR user>
Push the image to ACR:
docker push <your ACR URL>/tiny-yolov4-tflite:arm64v8-cuda-cudnn
Note:
Visual Studio Code (VSCode) will be used for the following. The following will be needed:
edge-module/deployment.yolov4.gpu.jetson.blob.template.json)When the Live Video Analytics on Edge direct methods are invoked (through the LVA console app) on device with the console app, images will appear in a folder with the name of your local container e.g. /media/nvme/blob_storage/BlockBlob/annotatedimageslocal and with default deployment manifest, will stick around on device for 60 minutes as well as being uploaded to the cloud Blob Storage container (in this example, called annotated-images-yolo4).
Steps:
.env parameters file within the edge-module folder with the following contents:SUBSCRIPTION_ID_FOR_AMS=<Azure subscription associated with the AMS account>
RESOURCE_GROUP_FOR_AMS=<Resource Group where the AMS account resides>
AMS_ACCOUNT=<AMS account name>
IOTHUB_CONNECTION_STRING="<IoT Hub connection string>"
AAD_TENANT_ID=<Active Directory tenant ID>
AAD_SERVICE_PRINCIPAL_ID=<Active Directory Service Principal ID associated with AMS>
AAD_SERVICE_PRINCIPAL_SECRET="<Service Principal secret/key associated with AMS>"
INPUT_VIDEO_FOLDER_ON_DEVICE="<input video folder on device for the media server>"
OUTPUT_VIDEO_FOLDER_ON_DEVICE="<output video folder on device to sink video clips from LVA>"
OUTPUT_BLOB_FOLDER_ON_DEVICE="<output folder for Blob Storage data>"
APPDATA_FOLDER_ON_DEVICE="/var/lib/azuremediaservices"
CONTAINER_REGISTRY_USERNAME_myacr=<ACR username>
CONTAINER_REGISTRY_PASSWORD_myacr=<ACR key>
CLOUD_STORAGE_CONN_STRING="<Azure Blob Storage cloud connection string>"
LOCAL_STORAGE_ACCOUNT_NAME="<local Edge Storage account name>"
LOCAL_STORAGE_ACCOUNT_KEY="<local Edge Storage account key>"
These variables, from the .env, will be automatically populated into the IoT Edge deployment manifest file after a deployment manifest file is generated from the template.
From VSCode, messages to IoT Hub should look similar to:
[IoTHubMonitor] [1:11:41 PM] Message received from [xavier-yolov4/lvaEdge]:
{
"inferences": [
{
"type": "entity",
"entity": {
"tag": {
"value": "car",
"confidence": "0.43346554"
},
"box": {
"l": "0.6137574",
"t": "0.5797131",
"w": "0.05888599",
"h": "0.047415733"
}
}
},
{
"type": "entity",
"entity": {
"tag": {
"value": "truck",
"confidence": "0.33760804"
},
"box": {
"l": "0.6137574",
"t": "0.5797131",
"w": "0.05888599",
"h": "0.047415733"
}
}
}
]
}
Notes:
Navigate to the web-app directory.
Create your environment variables as show in the example below and load them into the cu