ContainerImage Class
Represents a container image, currently only for Docker images.
This class is DEPRECATED. Use the Environment class instead.
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
Image constructor.
This class is DEPRECATED. Use the Environment class instead.
Image constructor is used to retrieve a cloud representation of a Image object associated with the provided workspace. Will return an instance of a child class corresponding to the specific type of the retrieved Image object.
- Inheritance
-
ContainerImage
Constructor
ContainerImage(workspace, name=None, id=None, tags=None, properties=None, version=None)
Parameters
- name
- str
The name of the Image to retrieve. Will return the latest version, if it exists
- tags
- list
Will filter Image results based on the provided list, by either 'key' or '[key, value]'. Ex. ['key', ['key2', 'key2 value']]
- properties
- list
Will filter Image results based on the provided list, by either 'key' or '[key, value]'. Ex. ['key', ['key2', 'key2 value']]
- version
- str
When version and name are both specified, will return the specific version of the Image.
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 to use in a 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",
cuda_version="9.0"
)
Methods
image_configuration |
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 |
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 object into a JSON serialized dictionary. |
image_configuration
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.
static 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, cuda_version=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.
- docker_file
- str
Path to local file containing additional Docker steps to run when setting up the image.
- 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.
List of paths to additional files/folders that the image needs to run.
- 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. Defaults to False
Dictionary of key value properties to give this image. These properties cannot be changed after deployment, however new key value pairs can be added.
- base_image
- str
A custom image to be used as base image. If no base image is given then the base image will be used based off of given runtime parameter.
- base_image_registry
- ContainerRegistry
Image registry that contains the base image.
- cuda_version
- str
Version of CUDA to install for images that need GPU support. 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. Supported versions are 9.0, 9.1, and 10.0. If 'enable_gpu' is set, this defaults to '9.1'.
Returns
A configuration object to use when creating the image.
Return type
Exceptions
run
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
- <xref:varies>
The input data to pass to the image when run
Returns
The results of running the image.
Return type
Exceptions
serialize
Convert this ContainerImage object into a JSON serialized dictionary.
serialize()
Returns
The JSON representation of this ContainerImage.
Return type
Exceptions
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for