ContainerImage 類別
表示容器映射,目前僅適用于 Docker 映射。
這個類別已被取代。 請改用 Environment 類別。
映射包含執行模型所需的相依性,包括:
執行時間
Conda 檔案中指定的 Python 環境定義
啟用 GPU 支援的能力
特定執行命令的自訂 Docker 檔案
影像建構函式。
這個類別已被取代。 請改用 Environment 類別。
影像建構函式是用來擷取與所提供工作區相關聯之 Image 物件的雲端標記法。 會傳回對應至所擷取 Image 物件之特定類型的子類別實例。
- 繼承
-
ContainerImage
建構函式
ContainerImage(workspace, name=None, id=None, tags=None, properties=None, version=None)
參數
- properties
- list
會依據提供的清單篩選影像結果,方法是 'key' 或 '[key, value]'。 例如 ['key', ['key2', 'key2 value']]
備註
使用類別建構函式擷取 Image ContainerImage,方法是傳遞先前建立 ContainerImage 的名稱或識別碼。 下列程式碼範例顯示依名稱和識別碼從工作區擷取影像。
container_image_from_name = Image(workspace, name="image-name")
container_image_from_id = Image(workspace, id="image-id")
若要建立要用於部署的新映射組態,請建 ContainerImageConfig 置 物件,如下列程式碼範例所示:
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"
)
方法
image_configuration |
建立並傳回 ContainerImageConfig 物件。 此函式接受參數來定義模型在 Webservice 中應如何執行,以及它必須能夠執行的特定環境和相依性。 |
run |
使用指定的輸入資料在本機執行映射。 必須安裝並執行 Docker 才能運作。 此方法只能在 CPU 上運作,因為已啟用 GPU 的映射只能在 Microsoft Azure 服務上執行。 |
serialize |
將此 ContainerImage 物件轉換成 JSON 序列化字典。 |
image_configuration
建立並傳回 ContainerImageConfig 物件。
此函式接受參數來定義模型在 Webservice 中應如何執行,以及它必須能夠執行的特定環境和相依性。
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)
參數
- execution_script
- str
本機 Python 檔案的路徑,其中包含要針對映射執行的程式碼。 必須同時包含 init () 並執行 (input_data) 函式,以定義 Webservice 的模型執行步驟。
- enable_gpu
- bool
是否要在映射中啟用 GPU 支援。 GPU 映射必須用於 Microsoft Azure 服務,例如 Azure 容器執行個體、Azure Machine Learning Compute、Azure 虛擬機器 和 Azure Kubernetes Service。 預設為 False
- cuda_version
- str
要針對需要 GPU 支援的映射安裝 CUDA 版本。 GPU 映射必須用於 Microsoft Azure 服務,例如 Azure 容器執行個體、Azure Machine Learning Compute、Azure 虛擬機器 和 Azure Kubernetes Service。 支援的版本為 9.0、9.1 和 10.0。 如果已設定 'enable_gpu',則預設為 '9.1'。
傳回
建立映射時要使用的組態物件。
傳回類型
例外狀況
run
使用指定的輸入資料在本機執行映射。
必須安裝並執行 Docker 才能運作。 此方法只能在 CPU 上運作,因為已啟用 GPU 的映射只能在 Microsoft Azure 服務上執行。
run(input_data)
參數
- input_data
- <xref:varies>
執行時要傳遞至映射的輸入資料
傳回
執行映射的結果。
傳回類型
例外狀況
serialize
將此 ContainerImage 物件轉換成 JSON 序列化字典。
serialize()
傳回
這個 ContainerImage 的 JSON 標記法。
傳回類型
例外狀況
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應