请使用MLClient设置默认工作区



获取错误"请使用"MLClient"设置默认工作区;。如何使用MLClient设置默认工作区?尝试使用数据资产https://learn.microsoft.com/en-us/azure/machine-learning/how-to-create-register-data-assets?tabs=Python-SDK

from azure.ai.ml.entities import Data
from azure.ai.ml.constants import AssetTypes
from azure.ai.ml import MLClient
#Enter details of your AzureML workspace
subscription_id = "<SUBSCRIPTION_ID>"
resource_group = "<RESOURCE_GROUP>"
workspace = "<AZUREML_WORKSPACE_NAME>"
ml_client = MLClient(subscription_id, resource_group, workspace)
data_location='path'
my_data = Data(
path=data_loacation,
type=AssetTypes.URI_FOLDER,
description="Data",
name="Data_test")
ml_client.data.create_or_update(my_data)

获取错误"请使用"MLClient"设置默认工作区;。如何使用MLClient设置默认工作区?

确保已使用pip install --pre azure-ai-ml安装Python SDK azure-ai-ml v2(preview)

您可以尝试从workspace.ipynb获取以下代码片段,以使用MLClient设置默认工作区:

导入所需库

from azure.ai.ml import MLClient
from azure.ai.ml.entities import Workspace
from azure.identity import DefaultAzureCredential
ml_client = MLClient(DefaultAzureCredential(), subscription_id, resource_group)

使用当前日期时间创建唯一的工作区名称以避免冲突

import datetime
basic_workspace_name = "mlw-basic-prod-" + datetime.datetime.now().strftime(
"%Y%m%d%H%M"
)
ws_basic = Workspace(
name=basic_workspace_name,
location="eastus",
display_name="Basic workspace-example",
description="This example shows how to create a basic workspace",
hbi_workspace=False,
tags=dict(purpose="demo"),
)
ml_client.workspaces.begin_create(ws_basic)

获取资源组中的工作区列表

for ws in my_ml_client.workspaces.list():
print(ws.name, ":", ws.location, ":", ws.description)

使用参数加载特定工作区

ws = MLClient(DefaultAzureCredential(), subscription_id='<SUBSCRIPTION_ID>', resource_group_name='<RESOURCE_GROUP>', workspace_name='<AML_WORKSPACE_NAME>')

我建议用实际值替换<SUBSCRIPTION_ID><RESOURCE_GROUP><AZUREML_WORKSPACE_NAME>
如果执行此操作,MLClient构造函数将相应地设置工作区。

相关内容

最新更新