You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In this article, learn how to use a custom Docker image when you're training models with Azure Machine Learning. You'll use the example scripts in this article to classify pet images by creating a convolutional neural network.
22
+
This article describes how to use a custom Docker image to train models with Azure Machine Learning. Example scripts show how to classify images by creating a convolutional neural network.
21
23
22
-
Azure Machine Learning provides a default Docker base image. You can also use Azure Machine Learning environments to specify a different base image, such as one of the maintained [Azure Machine Learning base images](https://github.com/Azure/AzureML-Containers) or your own [custom image](../how-to-deploy-custom-container.md). Custom base images allow you to closely manage your dependencies and maintain tighter control over component versions when running training jobs.
24
+
Azure Machine Learning provides a default Docker base image. You can also use Azure Machine Learning environments to specify a different base image, such as a maintained [Azure Machine Learning base image](https://github.com/Azure/AzureML-Containers) or your own [custom image](../how-to-deploy-custom-container.md). Custom base images allow you to closely manage your dependencies and maintain tighter control over component versions when you run training jobs.
23
25
24
26
## Prerequisites
25
27
26
-
Run the code on either of these environments:
28
+
To run the example code, your configuration must include one of the following environments:
29
+
30
+
- Azure Machine Learning compute instance with a dedicated notebook server preloaded with the Machine Learning SDK and Samples repository.
31
+
32
+
This configuration requires no downloads or other installation. To prepare this environment, see [Create resources to get started](../quickstart-create-resources.md).
33
+
34
+
- Jupyter Notebook server. The following resources provide instructions to help you prepare this environment:
27
35
28
-
* Azure Machine Learning compute instance (no downloads or installation necessary):
29
-
* Complete the [Create resources to get started](../quickstart-create-resources.md) tutorial to create a dedicated notebook server preloaded with the SDK and the sample repository.
30
-
* Your own Jupyter Notebook server:
31
-
* Create a [workspace configuration file](../how-to-configure-environment.md#local-and-dsvm-only-create-a-workspace-configuration-file).
32
-
* Install the [Azure Machine Learning SDK](/python/api/overview/azure/ml/install).
33
-
* Create an [Azure container registry](/azure/container-registry/) or other Docker registry that's available on the internet.
36
+
- Create a [workspace configuration file](../how-to-configure-environment.md#local-and-dsvm-only-create-a-workspace-configuration-file).
37
+
- Install the [Azure Machine Learning SDK](/python/api/overview/azure/ml/install).
38
+
- Create an [Azure container registry](/azure/container-registry/) or other Docker registry available on the internet.
34
39
35
40
## Set up a training experiment
36
41
37
-
In this section, you set up your training experiment by initializing a workspace, defining your environment, and configuring a compute target.
42
+
The first task is to set up your training experiment by initializing a Machine Learning workspace, defining your environment, and configuring a compute target.
38
43
39
44
### Initialize a workspace
40
45
41
-
The [Azure Machine Learning workspace](../concept-workspace.md) is the top-level resource for the service. It gives you a centralized place to work with all the artifacts that you create. In the Python SDK, you can access the workspace artifacts by creating a [`Workspace`](/python/api/azureml-core/azureml.core.workspace.workspace) object.
46
+
The [Azure Machine Learning workspace](../concept-workspace.md) is the top-level resource for the service. It gives you a centralized place to work with all the artifacts you create. In the Python SDK, you can access the workspace artifacts by creating a [`Workspace`](/python/api/azureml-core/azureml.core.workspace.workspace) object.
42
47
43
-
Create a `Workspace` object from the config.json file that you created as a [prerequisite](#prerequisites).
48
+
As needed, create a `Workspace` object from the config.json file that you created as a [prerequisite](#prerequisites).
The specified base image in the following code supports the fast.ai library, which allows for distributed deep-learning capabilities. For more information, see the [fast.ai Docker Hub repository](https://hub.docker.com/u/fastdotai).
62
67
63
-
When you're using your custom Docker image, you might already have your Python environment properly set up. In that case, set the `user_managed_dependencies` flag to `True` to use your custom image's built-in Python environment. By default, Azure Machine Learning builds a Conda environment with dependencies that you specified. The service runs the script in that environment instead of using any Python libraries that you installed on the base image.
68
+
When you use your custom Docker image, you might already have your Python environment properly set up. In that case, set the `user_managed_dependencies` flag to `True` to use your custom image's built-in Python environment. By default, Azure Machine Learning builds a Conda environment with dependencies that you specified. The service runs the script in that environment instead of using any Python libraries that you installed on the base image.
To use an image from a private container registry that isn't in your workspace, use `docker.base_image_registry` to specify the address of the repository and a username and password:
It's also possible to use a custom Dockerfile. Use this approach if you need to install non-Python packages as dependencies. Remember to set the base image to `None`.
84
89
85
90
```python
86
-
# Specify Docker steps as a string.
91
+
# Specify Docker steps as a string
87
92
dockerfile =r"""
88
93
FROM mcr.microsoft.com/azureml/openmpi3.1.2-ubuntu18.04:20210615.v1
89
94
RUN echo "Hello from custom container!"
90
95
"""
91
96
92
-
# Set the base image to None, because the image is defined by Dockerfile.
97
+
# Set the base image to None, because the image is defined by Dockerfile
93
98
fastai_env.docker.base_image =None
94
99
fastai_env.docker.base_dockerfile = dockerfile
95
100
96
-
# Alternatively, load the string from a file.
101
+
# Alternatively, load the string from a file
97
102
fastai_env.docker.base_image =None
98
103
fastai_env.docker.base_dockerfile ="./Dockerfile"
99
104
```
100
105
101
-
>[!IMPORTANT]
106
+
>[!IMPORTANT]
102
107
> Azure Machine Learning only supports Docker images that provide the following software:
103
-
> * Ubuntu 18.04 or greater.
104
-
> * Conda 4.7.# or greater.
105
-
> * Python 3.7+.
106
-
> * A POSIX compliant shell available at /bin/sh is required in any container image used for training.
108
+
> * Ubuntu 18.04 or greater
109
+
> * Conda 4.7.# or greater
110
+
> * Python 3.7+
111
+
> * A POSIX compliant shell available at /bin/sh is required in any container image used for training
107
112
108
113
For more information about creating and managing Azure Machine Learning environments, see [Create and use software environments](../how-to-use-environments.md).
109
114
@@ -119,7 +124,7 @@ As with other Azure services, there are limits on certain resources (for example
119
124
from azureml.core.compute import ComputeTarget, AmlCompute
120
125
from azureml.core.compute_target import ComputeTargetException
> Azure Machine Learning runs training scripts by copying the entire source directory. If you have sensitive data that you don't want to upload, use an [.ignore file](../concept-train-machine-learning-model.md#understand-what-happens-when-you-submit-a-training-job) or don't include it in the source directory. Instead, access your data by using a [datastore](/python/api/azureml-core/azureml.data).
175
178
176
-
## Next steps
177
-
In this article, you trained a model by using a custom Docker image. See these other articles to learn more about Azure Machine Learning:
178
-
*[Track run metrics](../how-to-log-view-metrics.md) during training.
179
-
*[Deploy a model](../how-to-deploy-custom-container.md) by using a custom Docker image.
179
+
## Related content
180
+
181
+
*[Track run metrics](../how-to-log-view-metrics.md)
182
+
*[Deploy a model by using a custom Docker image](../how-to-deploy-custom-container.md)
0 commit comments