Lab 3 - Deploy your model

In this lab we are going to deploy the model wrappend in an API in an Azure Container Instance and sending data to it with postman.

1. Deploy to an Azure Container Instance

Download the scoring script

inference_folder = "./inference"

inference_script_url = "https://raw.githubusercontent.com/hnky/DevelopersGuideToAI/master/amls/resources/score.py"
inference_script_download_path = os.path.join(inference_folder,"score.py")
if not os.path.exists(inference_folder):
    os.mkdir(inference_folder);
urllib.request.urlretrieve(inference_script_url, filename=inference_script_download_path)

Create an inference environment

inference_env = Environment(name="simpsons-inference")

conda_dep = CondaDependencies()
conda_dep.add_pip_package("azureml-defaults")
conda_dep.add_pip_package("torch")
conda_dep.add_pip_package("torchvision")
conda_dep.add_pip_package("pillow==5.4.1")

inference_env.python.conda_dependencies=conda_dep

Create an Inference config

Create a Azure Container Instance deployment config

Deploy the model to an ACI

This step can take up to 10 minutes

You can find the deployment location from your model back under the model: https://ml.azure.com

Note: if you don't see it immediately refresh the tab

Scoring URL

2. Test the model in the API

Post an image to the endpoint

The easiest way to test your scoring endpoint is the code below.

Use Postman

  • Get the scoring uri

  • Create a new request in Postman

    • POST request

    • Put scoring URL in call

  • Send a raw body with the JSON below. Make sure JSON is selected in orange next to the raw radio button

Scoring URL

Try other images

End

Last updated

Was this helpful?