ContainerImage class

Definition

Class for container images, currently only for Docker images.

The image contains the dependencies needed to run the model including:

  • The runtime

  • Python environment definitions specified in a Conda file

  • Ability to enable GPU support

  • Custom Docker file for specific run commands

ContainerImage(workspace, name=None, id=None, tags=None, properties=None, version=None)
Inheritance
ContainerImage

Remarks

A ContainerImage is retrieved using the Image class constructor by passing the name or id of a previously created ContainerImage. The following code example shows an Image retrieval from a Workspace by both name and id.


   container_image_from_name = Image(workspace, name="image-name")
   container_image_from_id = Image(workspace, id="image-id")

To create a new Image configuration for use in deployment, build a ContainerImageConfig object as shown in the following code example:


   from azureml.core.image import ContainerImage

   image_config = ContainerImage.image_configuration(execution_script="score.py",
                                                    runtime="python",
                                                    conda_file="myenv.yml",
                                                    description="image for model",
                                                    enable_gpu=True
                                                    )

See the following link for an overview on deploying models in Azure: https://aka.ms/azureml-how-deploy

See https://docs.microsoft.com/en-us/azure/machine-learning/service/tutorial-deploy-models-with-aml for an example of how to create a Webservice using this Image configuration.

Methods

image_configuration(execution_script, runtime, conda_file=None, docker_file=None, schema_file=None, dependencies=None, enable_gpu=None, tags=None, properties=None, description=None, base_image=None, base_image_registry=None)

Create and return a ContainerImageConfig object.

This function accepts parameters to define how your model should run within the Webservice, as well as the specific environment and dependencies it needs to be able to run.

run(input_data)

Run the image locally with the given input data.

Must have Docker installed and running to work. This method will only work on CPU, as the GPU-enabled image can only run on Microsoft Azure Services.

serialize()

Convert this ContainerImage into a json serialized dictionary.

image_configuration(execution_script, runtime, conda_file=None, docker_file=None, schema_file=None, dependencies=None, enable_gpu=None, tags=None, properties=None, description=None, base_image=None, base_image_registry=None)

Create and return a ContainerImageConfig object.

This function accepts parameters to define how your model should run within the Webservice, as well as the specific environment and dependencies it needs to be able to run.

image_configuration(execution_script, runtime, conda_file=None, docker_file=None, schema_file=None, dependencies=None, enable_gpu=None, tags=None, properties=None, description=None, base_image=None, base_image_registry=None)

Parameters

execution_script
str

Path to local Python file that contains the code to run for the image. Must include both init() and run(input_data) functions that define the model execution steps for the Webservice.

runtime
str

The runtime to use for the image. Current supported runtimes are 'spark-py' and 'python'.

conda_file
str

Path to local .yml file containing a Conda environment definition to use for the image.

default value: None
docker_file
str

Path to local file containing additional Docker steps to run when setting up the image.

default value: None
schema_file
str

Path to local file containing a webservice schema to use when the image is deployed. Used for generating Swagger specs for a model deployment.

default value: None
dependencies
<xref:azureml.core.image.list[str]>

List of paths to additional files/folders that the image needs to run.

default value: None
enable_gpu
bool

Whether or not to enable GPU support in the image. The GPU image must be used on Microsoft Azure Services such as Azure Container Instances, Azure Machine Learning Compute, Azure Virtual Machines, and Azure Kubernetes Service.

default value: None
tags
dict[str or str]

Dictionary of key value tags to give this image.

default value: None
properties
dict[str or str]

Dictionary of key value properties to give this image. These properties cannot be changed after deployment, however new key value pairs can be added.

default value: None
description
str

A text description to give this image.

default value: None
base_image
str

A custom image to be used as base image.

default value: None
base_image_registry
ContainerRegistry

Image registry that contains the base image.

default value: None

Returns

A configuration object to use when creating the image.

Return type

run(input_data)

Run the image locally with the given input data.

Must have Docker installed and running to work. This method will only work on CPU, as the GPU-enabled image can only run on Microsoft Azure Services.

run(input_data)

Parameters

input_data
varies

The input data to pass to the image when run

Returns

The results of running the image.

Return type

varies

serialize()

Convert this ContainerImage into a json serialized dictionary.

serialize()

Returns

The json representation of this Image

Return type