Deploy an AI-based footfall detection solution using Azure and Azure Stack Hub

This article describes how to deploy an AI-based solution that generates insights from real world actions by using Azure, Azure Stack Hub, and the Custom Vision AI Dev Kit.

In this solution, you learn how to:

  • Deploy Cloud Native Application Bundles (CNAB) at the edge.
  • Deploy an app that spans cloud boundaries.
  • Use the Custom Vision AI Dev Kit for inference at the edge.

Tip

Hybrid pillars diagram Microsoft Azure Stack Hub is an extension of Azure. Azure Stack Hub brings the agility and innovation of cloud computing to your on-premises environment, enabling the only hybrid cloud that allows you to build and deploy hybrid apps anywhere.

The article Hybrid app design considerations reviews pillars of software quality (placement, scalability, availability, resiliency, manageability, and security) for designing, deploying, and operating hybrid apps. The design considerations assist in optimizing hybrid app design, minimizing challenges in production environments.

Prerequisites

Before getting started with this deployment guide, make sure you:

Deploy the hybrid cloud app

First you use the Porter CLI to generate a credential set, then deploy the cloud app.

  1. Clone or download the repository containing the solution sample code.

  2. Porter will generate a set of credentials that will automate deployment of the app. Before running the credential generation command, be sure to have the following available:

    • A service principal for accessing Azure resources, including the service principal ID, key, and tenant DNS.
    • The subscription ID for your Azure subscription.
    • A service principal for accessing Azure Stack Hub resources, including the service principal ID, key, and tenant DNS.
    • The subscription ID for your Azure Stack Hub subscription.
    • Your Azure Cognitive Services Face API key and resource endpoint URL.
  3. Run the Porter credential generation process and follow the prompts:

    porter creds generate --tag intelligentedge/footfall-cloud-deployment:0.1.0
    
  4. Porter also requires a set of parameters to run. Create a parameter text file and enter the following name/value pairs. Ask your Azure Stack Hub administrator if you need assistance with any of the required values.

    Note

    The resource suffix value is used to ensure that your deployment's resources have unique names across Azure. It must be a unique string of letters and numbers, no longer than 8 characters.

    azure_stack_tenant_arm="Your Azure Stack Hub tenant endpoint"
    azure_stack_storage_suffix="Your Azure Stack Hub storage suffix"
    azure_stack_keyvault_suffix="Your Azure Stack Hub keyVault suffix"
    resource_suffix="A unique string to identify your deployment"
    azure_location="A valid Azure region"
    azure_stack_location="Your Azure Stack Hub location identifier"
    powerbi_display_name="Your first and last name"
    powerbi_principal_name="Your Power BI account email address"
    

    Save the text file and make a note of its path.

  5. You're now ready to deploy the hybrid cloud app using Porter. Run the install command and watch as resources are deployed to Azure and Azure Stack Hub:

    porter install footfall-cloud –tag intelligentedge/footfall-cloud-deployment:0.1.0 –creds footfall-cloud-deployment –param-file "path-to-cloud-parameters-file.txt"
    
  6. Once deployment is complete, make note of the following values:

    • The camera's connection string.
    • The image storage account connection string.
    • The resource group names.

Prepare the Custom Vision AI DevKit

Next, set up the Custom Vision AI Dev Kit as shown in the Vision AI DevKit quickstart. You also set up and test your camera, using the connection string provided in the previous step.

Deploy the camera app

Use the Porter CLI to generate a credential set, then deploy the camera app.

  1. Porter will generate a set of credentials that will automate deployment of the app. Before running the credential generation command, be sure to have the following available:

    • A service principal for accessing Azure resources, including the service principal ID, key, and tenant DNS.
    • The subscription ID for your Azure subscription.
    • The image storage account connection string provided when you deployed the cloud app.
  2. Run the Porter credential generation process and follow the prompts:

    porter creds generate --tag intelligentedge/footfall-camera-deployment:0.1.0
    
  3. Porter also requires a set of parameters to run. Create a parameter text file and enter the following text. Ask your Azure Stack Hub administrator if you don't know some of the required values.

    Note

    The deployment suffix value is used to ensure that your deployment's resources have unique names across Azure. It must be a unique string of letters and numbers, no longer than 8 characters.

    iot_hub_name="Name of the IoT Hub deployed"
    deployment_suffix="Unique string here"
    

    Save the text file and make a note of its path.

  4. You're now ready to deploy the camera app using Porter. Run the install command and watch as the IoT Edge deployment is created.

    porter install footfall-camera –tag intelligentedge/footfall-camera-deployment:0.1.0 –creds footfall-camera-deployment –param-file "path-to-camera-parameters-file.txt"
    
  5. Verify that the camera's deployment is complete by viewing the camera feed at https://<camera-ip>:3000/, where <camara-ip> is the camera IP address. This step may take up to 10 minutes.

Configure Azure Stream Analytics

Now that data is flowing to Azure Stream Analytics from the camera, we need to manually authorize it to communicate with Power BI.

  1. From the Azure portal, open All Resources, and the process-footfall[yoursuffix] job.

  2. In the Job Topology section of the Stream Analytics job pane, select the Outputs option.

  3. Select the traffic-output output sink.

  4. Select Renew authorization and sign in to your Power BI account.

    Screenshot that shows the renew authorization prompt in Power BI.

  5. Save the output settings.

  6. Go to the Overview pane and select Start to start sending data to Power BI.

  7. Select Now for job output start time and select Start. You can view the job status in the notification bar.

Create a Power BI Dashboard

  1. Once the job succeeds, go to Power BI and sign in with your work or school account. If the Stream Analytics job query is outputting results, the footfall-dataset dataset you created exists under the Datasets tab.

  2. From your Power BI workspace, select + Create to create a new dashboard named Footfall Analysis.

  3. At the top of the window, select Add tile. Then select Custom Streaming Data and Next. Choose the footfall-dataset under Your Datasets. Select Card from the Visualization type dropdown, and add age to Fields. Select Next to enter a name for the tile, and then select Apply to create the tile.

  4. You can add additional fields and cards as desired.

Test Your Solution

Observe how the data in the cards you created in Power BI changes as different people walk in front of the camera. Inferences may take up to 20 seconds to appear once recorded.

Remove Your Solution

If you'd like to remove your solution, run the following commands using Porter, using the same parameter files that you created for deployment:

porter uninstall footfall-cloud –tag intelligentedge/footfall-cloud-deployment:0.1.0 –creds footfall-cloud-deployment –param-file "path-to-cloud-parameters-file.txt"

porter uninstall footfall-camera –tag intelligentedge/footfall-camera-deployment:0.1.0 –creds footfall-camera-deployment –param-file "path-to-camera-parameters-file.txt"

Next steps