Serverless image classification with Azure Functions and Custom Vision – Part 4

Post image

Welcome to the fourth part of the learning series “Serverless image classification with Azure Functions and Custom Vision”! In the previous articles, you built an image classification model that predicts whether a photo contains a dog or a cat and used the exported TensorFlow model in an Azure Function.

To find out more about previous posts, check out the links below:

In this article, you will deploy your function project to Azure to create a serverless HTTP API for image classification. You will learn how to:

  • Create an Azure Function App.
  • Publish your Azure Functions project to Azure.

To complete the exercise, you will need:

Create a function app in Azure

  1. Open your local function project in Visual Studio Code. Then, navigate to the Azure tab.

  2. If you are not already signed in, under Resources, select Sign in to Azure.

    Sign in to Azure in Visual Studio Code
  3. After you’ve successfully signed in, select the + button in the Resources area to create a new Azure resource.

  4. Then, select Create Function App in Azure.

    Create Function App in Azure
  5. Provide the following information when prompt:

    • Enter a globally unique name for the function app: Type a valid name. This name will be part of your function’s endpoint and must be unique.

      Enter a globally unique name for the function app
    • Select a runtime stack: Choose the Python version on which you’ve created your local function project. If you followed the instructions in the previous article, select Python 3.9.

      Select a runtime stack
    • Select a location for new resources: Choose a region near you.

      Select a location for the new Azure Function resource
  6. When the creation is complete, a notification is raised in Visual Studio Code.

Deploy the functions project to Azure

  1. Click on the Azure icon in the activity bar and under Workspace, select your local functions project.

  2. Select the deploy button and then choose Deploy to Function App…

    Deploy the local function project to Azure
  3. Choose the Function App you created in the previous step and then select Deploy.

  4. Wait for the deployment to be complete. Once the deployment is complete, you will see the function’s endpoint in the Output.

    Endpoint of the Azure Function app

Run the Azure Function

  1. Under Resources, expand your Function App projects, right-click on the classify function and choose Execute Function Now…

  2. In the request body enter { "img": "<URL>" }, where <URL> refers to the URL of an image.

  3. If the function runs correctly, a notification is raised in Visual Studio Code containing information about the function’s execution.

    Function's response

You can also test the function in your browser using: https://classifycatsdogs.azurewebsites.net/api/classify?img=<URL>.

Summary and next steps

In this article, you learned how to deploy the Azure Functions project to Azure using Visual Studio Code.

If you are interested in learning more about Azure Functions, you may check out the following resources:

You May Also Like