Webservice class

Definition

Class for Azure Machine Learning Webservices.

Webservice constructor is used to retrieve a cloud representation of a Webservice object associated with the provided Workspace. Returns an instance of a child class corresponding to the specific type of the retrieved Webservice object. Class allows for deploying machine learning models from either a Model or Image object. See the following how-to for code examples: https://docs.microsoft.com/azure/machine-learning/service/how-to-deploy-and-where

Webservice(workspace, name)
Inheritance
builtins.object
Webservice

Parameters

workspace
Workspace

The workspace object containing the Webservice object to retrieve

name
str

The name of the Webservice object to retrieve

Methods

delete()

Delete this Webservice from its associated workspace.

This function call is not asynchronous; it runs until the resource is deleted.

deploy(workspace, name, model_paths, image_config, deployment_config=None, deployment_target=None)

Deploy a Webservice from zero or more model files.

This will register any models files provided and create an image in the process, all associated with the specified Workspace. Use this function when you have a directory of models to deploy that haven't been previously registered.

deploy_from_image(workspace, name, image, deployment_config=None, deployment_target=None)

Deploy a Webservice from an Image object.

Use this function if you already have an Image object created for a model.

deploy_from_model(workspace, name, models, image_config, deployment_config=None, deployment_target=None)

Deploy a Webservice from zero or more model objects.

This function is similar to deploy(workspace, name, model_paths, image_config, deployment_config=None, deployment_target=None), but does not register(workspace, model_path, model_name, tags=None, properties=None, description=None, datasets=None, model_framework=None, model_framework_version=None) the models. Use this function if you have model objects that are already registered. This will create an image in the process, associated with the specified Workspace.

deploy_local_from_model(workspace, name, models, image_config, deployment_config=None, wait=False)

Build and deploy a LocalWebservice for testing. Requires Docker to be installed and configured.

deserialize(workspace, webservice_payload)

Convert a json object generated from <xref:azureml.core.webservice.webservice.serialize> into a Webservice object.

Will fail if the provided workspace is not the workspace the Webservice is registered under.

get_keys()

Retrieve auth keys for this Webservice.

get_logs(num_lines=5000)

Retrieve logs for this Webservice.

list(workspace, compute_type=None, image_name=None, image_id=None, model_name=None, model_id=None, tags=None, properties=None)

List the Webservices associated with the corresponding Workspace. Can be filtered with specific parameters.

regen_key(key)

Regenerate one of the Webservice's keys. Must specify either 'Primary' or 'Secondary' key.

run(input)

Call this Webservice with the provided input.

Abstract method implemented by child classes of Webservice.

serialize()

Convert this Webservice into a json serialized dictionary.

Use deserialize(workspace, webservice_payload) to convert back into a Webservice object.

update(*args)

Update the Webservice parameters.

Abstract method implemented by child classes of Webservice. Possible parameters to update vary based on Webservice child type. For Azure Container Instances webservices, see update(image=None, tags=None, properties=None, description=None, auth_enabled=None, ssl_enabled=None, ssl_cert_pem_file=None, ssl_key_pem_file=None, ssl_cname=None, enable_app_insights=None, models=None, inference_config=None) for specific parameters.

update_deployment_state()

Refresh the current state of the in-memory object.

Perform an in-place update of the properties of the object based on the current state of the corresponding cloud object. Primarily useful for manual polling of creation state.

wait_for_deployment(show_output=False)

Automatically poll on the running Webservice deployment.

Wait for the Webservice to reach a terminal state. Will throw a WebserviceException if it reaches a non-successful terminal state.

delete()

Delete this Webservice from its associated workspace.

This function call is not asynchronous; it runs until the resource is deleted.

delete()

deploy(workspace, name, model_paths, image_config, deployment_config=None, deployment_target=None)

Deploy a Webservice from zero or more model files.

This will register any models files provided and create an image in the process, all associated with the specified Workspace. Use this function when you have a directory of models to deploy that haven't been previously registered.

deploy(workspace, name, model_paths, image_config, deployment_config=None, deployment_target=None)

Parameters

workspace
Workspace

A Workspace object to associate the Webservice with

name
str

The name to give the deployed service. Must be unique to the workspace.

model_paths
<xref:azureml.core.webservice.webservice.list[str]>

A list of on-disk paths to model files or folder. Can be an empty list.

image_config
ImageConfig

An ImageConfig object used to determine required Image properties.

deployment_config
WebserviceDeploymentConfiguration

A WebserviceDeploymentConfiguration used to configure the webservice. If one is not provided, an empty configuration object will be used based on the desired target.

default value: None
deployment_target
ComputeTarget

A ComputeTarget to deploy the Webservice to. As Azure Container Instances has no associated ComputeTarget, leave this parameter as None to deploy to Azure Container Instances.

default value: None

Returns

A Webservice object corresponding to the deployed webservice

Return type

deploy_from_image(workspace, name, image, deployment_config=None, deployment_target=None)

Deploy a Webservice from an Image object.

Use this function if you already have an Image object created for a model.

deploy_from_image(workspace, name, image, deployment_config=None, deployment_target=None)

Parameters

workspace
Workspace

A Workspace object to associate the Webservice with

name
str

The name to give the deployed service. Must be unique to the workspace.

image
Image

An Image object to deploy.

deployment_config
WebserviceDeploymentConfiguration

A WebserviceDeploymentConfiguration used to configure the webservice. If one is not provided, an empty configuration object will be used based on the desired target.

default value: None
deployment_target
ComputeTarget

A ComputeTarget to deploy the Webservice to. As Azure Container Instances has no associated ComputeTarget, leave this parameter as None to deploy to Azure Container Instances.

default value: None

Returns

A Webservice object corresponding to the deployed webservice

Return type

deploy_from_model(workspace, name, models, image_config, deployment_config=None, deployment_target=None)

Deploy a Webservice from zero or more model objects.

This function is similar to deploy(workspace, name, model_paths, image_config, deployment_config=None, deployment_target=None), but does not register(workspace, model_path, model_name, tags=None, properties=None, description=None, datasets=None, model_framework=None, model_framework_version=None) the models. Use this function if you have model objects that are already registered. This will create an image in the process, associated with the specified Workspace.

deploy_from_model(workspace, name, models, image_config, deployment_config=None, deployment_target=None)

Parameters

workspace
Workspace

A Workspace object to associate the Webservice with

name
str

The name to give the deployed service. Must be unique to the workspace.

models
<xref:list[Model]>

A list of model objects. Can be an empty list.

image_config
ImageConfig

An ImageConfig object used to determine required Image properties.

deployment_config
WebserviceDeploymentConfiguration

A WebserviceDeploymentConfiguration used to configure the webservice. If one is not provided, an empty configuration object will be used based on the desired target.

default value: None
deployment_target
ComputeTarget

A ComputeTarget to deploy the Webservice to. As ACI has no associated ComputeTarget, leave this parameter as None to deploy to ACI.

default value: None

Returns

A Webservice object corresponding to the deployed webservice

Return type

deploy_local_from_model(workspace, name, models, image_config, deployment_config=None, wait=False)

Build and deploy a LocalWebservice for testing. Requires Docker to be installed and configured.

deploy_local_from_model(workspace, name, models, image_config, deployment_config=None, wait=False)

Parameters

workspace
Workspace

A Workspace object with which to associate the Webservice.

name
str

The name to give the deployed service. Must be unique on the local machine.

models
<xref:list[Model]>

A list of model objects. Can be an empty list.

image_config
ImageConfig

An ImageConfig object used to determine required service image properties.

deployment_config
LocalWebserviceDeploymentConfiguration

A LocalWebserviceDeploymentConfiguration used to configure the webservice. If one is not provided, an empty configuration object will be used.

default value: None
wait
bool

Wait for the LocalWebservice's Docker container to report as healthy. Throws an exception if the container crashes.

default value: False

Return type

deserialize(workspace, webservice_payload)

Convert a json object generated from <xref:azureml.core.webservice.webservice.serialize> into a Webservice object.

Will fail if the provided workspace is not the workspace the Webservice is registered under.

deserialize(workspace, webservice_payload)

Parameters

cls
workspace
Workspace

The workspace object the Webservice is registered under

webservice_payload
dict

A json object to convert to a Webservice object

Returns

The Webservice representation of the provided json object

Return type

get_keys()

Retrieve auth keys for this Webservice.

get_keys()

Returns

The auth keys for this Webservice

Return type

(str, str)

get_logs(num_lines=5000)

Retrieve logs for this Webservice.

get_logs(num_lines=5000)

Parameters

num_lines
int

The maximum number of log lines to retrieve

default value: 5000

Returns

The logs for this Webservice

Return type

str

list(workspace, compute_type=None, image_name=None, image_id=None, model_name=None, model_id=None, tags=None, properties=None)

List the Webservices associated with the corresponding Workspace. Can be filtered with specific parameters.

list(workspace, compute_type=None, image_name=None, image_id=None, model_name=None, model_id=None, tags=None, properties=None)

Parameters

workspace
Workspace

The Workspace object to list the Webservices in.

compute_type
str

Filter to list only specific Webservice types. Options are 'ACI', 'AKS'.

default value: None
image_name
str

Filter list to only include Webservices deployed with the specific image name

default value: None
image_id
str

Filter list to only include Webservices deployed with the specific image id

default value: None
model_name
str

Filter list to only include Webservices deployed with the specific model name

default value: None
model_id
str

Filter list to only include Webservices deployed with the specific model id

default value: None
tags
<xref:azureml.core.webservice.webservice.Webservice.list>

Will filter based on the provided list, by either 'key' or '[key, value]'. Ex. ['key', ['key2', 'key2 value']]

default value: None
properties
<xref:azureml.core.webservice.webservice.Webservice.list>

Will filter based on the provided list, by either 'key' or '[key, value]'. Ex. ['key', ['key2', 'key2 value']]

default value: None

Returns

A filtered list of Webservices in the provided Workspace

Return type

<xref:azureml.core.webservice.webservice.list[Webservice]>

regen_key(key)

Regenerate one of the Webservice's keys. Must specify either 'Primary' or 'Secondary' key.

regen_key(key)

Parameters

key
str

Which key to regenerate. Options are 'Primary' or 'Secondary'

run(input)

Call this Webservice with the provided input.

Abstract method implemented by child classes of Webservice.

run(input)

Parameters

input
varies

The input data to call the Webservice with. This is the data your machine learning model expects as an input to run predictions.

Returns

The result of calling the Webservice. This will return predictions run from your machine learning model.

Return type

serialize()

Convert this Webservice into a json serialized dictionary.

Use deserialize(workspace, webservice_payload) to convert back into a Webservice object.

serialize()

Returns

The json representation of this Webservice

Return type

update(*args)

Update the Webservice parameters.

Abstract method implemented by child classes of Webservice. Possible parameters to update vary based on Webservice child type. For Azure Container Instances webservices, see update(image=None, tags=None, properties=None, description=None, auth_enabled=None, ssl_enabled=None, ssl_cert_pem_file=None, ssl_key_pem_file=None, ssl_cname=None, enable_app_insights=None, models=None, inference_config=None) for specific parameters.

update(*args)

Parameters

args
varies

Values to update

update_deployment_state()

Refresh the current state of the in-memory object.

Perform an in-place update of the properties of the object based on the current state of the corresponding cloud object. Primarily useful for manual polling of creation state.

update_deployment_state()

wait_for_deployment(show_output=False)

Automatically poll on the running Webservice deployment.

Wait for the Webservice to reach a terminal state. Will throw a WebserviceException if it reaches a non-successful terminal state.

wait_for_deployment(show_output=False)

Parameters

show_output
bool

Option to print more verbose output

default value: False