az-deep-realtime-score/Keras_Tensorflow/00_AMLSetup.ipynb

223 строки
6.0 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Installation and configuration¶\n",
"\n",
"This notebook configures the notebooks in this tutorial to connect to an Azure Machine Learning (AML) Workspace. You can use an existing workspace or create a new one."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import azureml.core\n",
"from azureml.core import Workspace\n",
"from dotenv import set_key, get_key, find_dotenv\n",
"from pathlib import Path"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Prerequisites \n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If you have already completed the prerequisites, you can execute following command to ensure you are using correct conda environment. The output of this command should contain \"tutorial_env\" in the path, e.g. `/anaconda/envs/tutorial_env/bin/python`"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"/anaconda/envs/tutorial_env/bin/python\r\n"
]
}
],
"source": [
"!which python"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The AML Python SDK is already installed. Let's check the AML SDK version."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(\"SDK Version:\", azureml.core.VERSION)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# register the new resource provider\n",
"!az provider register -n Microsoft.MachineLearningServices\n",
"\n",
"# check the registration status\n",
"!az provider show -n Microsoft.MachineLearningServices"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"subscription_id_query = !az account show --query id -o tsv\n",
"subscription_id = subscription_id_query.s"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"tags": [
"parameters"
]
},
"outputs": [],
"source": [
"resource_group ='<YOUR_RESOURCE_GROUP>' # e.g. myamlrg\n",
"workspace_name = '<YOUR_WORKSPACE_NAME>' # e.g. myamlworkspace\n",
"workspace_region ='<YOUR_WORKSPACE_REGION>' # e.g. eastus2"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Create and initialize a dotenv file for storing parameters used in multiple notebooks."
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"env_path = find_dotenv()\n",
"if env_path == \"\":\n",
" Path(\".env\").touch()\n",
" env_path = find_dotenv()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"set_key(env_path, 'resource_group', resource_group)\n",
"set_key(env_path, 'workspace_name', workspace_name)\n",
"set_key(env_path, 'workspace_region', workspace_region)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create the workspace\n",
"This cell will create an AML workspace for you in a subscription, provided you have the correct permissions.\n",
"This will fail when:\n",
"\n",
"1. You do not have permission to create a workspace in the resource group\n",
"2. You do not have permission to create a resource group if it's non-existing.\n",
"3. You are not a subscription owner or contributor and no Azure ML workspaces have ever been created in this subscription\n",
"\n",
"If workspace creation fails, please work with your IT admin to provide you with the appropriate permissions or to provision the required resources. If this cell succeeds, you're done configuring AML!"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# import the Workspace class and check the azureml SDK version\n",
"#from azureml.core import Workspace\n",
"\n",
"ws = Workspace.create(name = workspace_name,\n",
" subscription_id = subscription_id,\n",
" resource_group = resource_group, \n",
" location = workspace_region,\n",
" create_resource_group=True,\n",
" exist_ok=True)\n",
"# persist the subscription id, resource group name, and workspace name in aml_config/config.json.\n",
"ws.write_config()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Below we will reload it just to make sure that everything is working."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# load workspace configuratio from ./aml_config/config.json file.ß\n",
"my_workspace = Workspace.from_config()\n",
"my_workspace.get_details()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In this notebook, we created a \".env\" file to save and reuse the variables needed cross all the notebooks. We also created a new Azure resource group with name <YOUR\\_RESOURCE\\_GROUP>, where an AML workspace and a few other Azure resources are created. We can now move on to the next notebook [developing the model](01_DevelopModel.ipynb)."
]
}
],
"metadata": {
"celltoolbar": "Tags",
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.7"
}
},
"nbformat": 4,
"nbformat_minor": 2
}