Azure ML 机器学习: 创建 Workspace 以及获得 Workspace 的多种方法

Azure ML: 创建 Workspace 以及获得当前 Workspace 的多种方法

记录三种创建Azure Machine Learning Workspace的方法:Azure Portal, Azure Python SDK,Azure CLI,以及获得当前workspace的两个方法。



1 创建 Workspace

一般我们有三种办法创建 Azure Machine Learning Workspace(当然,前提是我们要有一个Azure的账号)。

1.1 通过 Azure Portal

我们可以直接通过Azure的前端:Azure Portal进行Workspace创建。进入Azure Portal的个人主页,找到Machine Learning,点进去之后点击Create,如下图:

在这里插入图片描述

需要注意的是,新建一个Workspace需要链接或者新建一个Azure Storage账户(用以保存数据),一个Azure Key Vault账户(用以保存密码),一个Azure Application insights账户(一些monitoring功能),以及一个Azure Container Registry账户(保存Container及其相关)。

1.2 通过 Python SDK

我们可以通过Azure Python SDK进行新建Workspace:

from azureml.core import Workspace
ws = Workspace.create(name='myworkspace',
    subscription_id='<azure-subscription-id>',
    resource_group='myresourcegroup',
    create_resource_group=True,
    location='eastus2'
    )

1.3 通过 Azure CLI

Azure还自带类似terminal指令的Azure CLI。在新建Workspace之前,我们需要先login:

az login

然后

az ml workspace create -g <resource-group-name> --file workspace.yml

这个workspace.yml包含:

$schema: https://azuremlschemas.azureedge.net/latest/workspace.schema.json
name: mlw-basicex-prod
location: eastus
display_name: Bring your own dependent resources-example
description: This configuration specifies a workspace configuration with existing dependent resources
storage_account: /subscriptions/<SUBSCRIPTION_ID>/resourceGroups/<RESOURCE_GROUP>/providers/Microsoft.Storage/storageAccounts/<STORAGE_ACCOUNT>
container_registry: /subscriptions/<SUBSCRIPTION_ID>/resourceGroups/<RESOURCE_GROUP>/providers/Microsoft.ContainerRegistry/registries/<CONTAINER_REGISTRY>
key_vault: /subscriptions/<SUBSCRIPTION_ID>/resourceGroups/<RESOURCE_GROUP>/providers/Microsoft.KeyVault/vaults/<KEY_VAULT>
application_insights: /subscriptions/<SUBSCRIPTION_ID>/resourceGroups/<RESOURCE_GROUP>/providers/Microsoft.insights/components/<APP_INSIGHTS>
tags:
  purpose: demonstration

当然,还有其他方式创建Azure Machine Learning Workspace,比如通过ARM 模板,用于CI/CD的yaml文档中。这里我们就不赘述了。

2 获得 Workspace

有两种方式,通过Azure Python SDK:

一种,当我们在Azure Machine Learning Studio中的Compute Instance创建了VM,登录进去,我们可以直接使用

from azureml.core.workspace import Workspace
ws = Workspace.from_config()

得到当前Workspace信息。不需要输入任何参数,因为我们运行环境本身就已经在这个Workspace里面了。

另外一种情况,是我们在本地环境下,则可以通过下面代码:

from azureml.core.workspace import Workspace
subscription_id = 'XXX'
resource_group = 'XXX'
workspace_name = 'XXX'
workspace = Workspace(subscription_id, resource_group, workspace_name)

即,我们需要输入三个参数:subscription id, resource group名称,以及workspace的名称。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

破浪会有时

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值