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.
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)
myenv = CondaDependencies.create(pip_packages=['azureml-defaults ', 'torch', 'torchvision','pillow==5.4.1'])with open("inference/myenv.yml","w") as f:f.write(myenv.serialize_to_string())myenv = Environment.from_conda_specification(name="myenv", file_path="inference/myenv.yml")
inference_config = InferenceConfig(entry_script="inference/score.py", environment=myenv)
deploy_config = AciWebservice.deploy_configuration(cpu_cores = model.resource_configuration.cpu,memory_gb = model.resource_configuration.memory_in_gb,description='Simpson Lego Classifier')
aci_service = Model.deploy(ws,name="simpsons-pt-aci",models = [model],inference_config = inference_config,deployment_config = deploy_config,overwrite = True)aci_service.wait_for_deployment(show_output=True)print("Scoring endpoint:",aci_service.scoring_uri)
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
The easiest way to test your scoring endpoint is the code below.
image_uri = "https://raw.githubusercontent.com/hnky/dataset-lego-figures/master/_test/Bart.jpg"result = aci_service.run(input_data=json.dumps({ "url": image_uri}))print(result)
Get the scoring uri
print("Scoring endpoint:",aci_service.scoring_uri)
Create a new request in Postman
Send a raw body with the JSON below
{ "url": "https://raw.githubusercontent.com/hnky/dataset-lego-figures/master/_test/Bart.jpg"}
https://raw.githubusercontent.com/hnky/dataset-lego-figures/master/_test/Krusty.jpghttps://raw.githubusercontent.com/hnky/dataset-lego-figures/master/_test/Bart.jpghttps://raw.githubusercontent.com/hnky/dataset-lego-figures/master/_test/Flanders.jpghttps://raw.githubusercontent.com/hnky/dataset-lego-figures/master/_test/Homer.jpghttps://raw.githubusercontent.com/hnky/dataset-lego-figures/master/_test/Lisa.jpghttps://raw.githubusercontent.com/hnky/dataset-lego-figures/master/_test/marge.jpghttps://raw.githubusercontent.com/hnky/dataset-lego-figures/master/_test/Milhouse.jpghttps://raw.githubusercontent.com/hnky/dataset-lego-figures/master/_test/MrBurns.jpghttps://raw.githubusercontent.com/hnky/dataset-lego-figures/master/_test/Wiggum.jpg
End