This guide provides step-by-step instructions for setting up and configuring your Azure Machine Learning environment using both PowerShell and Bash. Please replace placeholder values (e.g., <subscription-id>
, <workspace>
, <resource-group>
, <location>
) with your actual Azure subscription and resource details.
- Install AZ CLI
- Install AML Python SDK V2
- Install az ml CLI v2
- Run the following command to see the
az extension
az extension list
- If you see the
azure-cli-ml
extension, remove it by running the following command:az extension remove -n azure-cli-ml
- If you see
ml
extension, remove it by running the following command:az extension remove -n ml
- Install the latest az
ml
CLI v2 extension by running the following command:az extension add -n ml -y
- Run the following command to see the
- git clone repo git clone https://github.com/anildwarepo/amlvision-mlops
PowerShell:
az login
az account set -s <subscription-id>
az configure --defaults workspace=<workspace> group=<resource-group> location=<location>
az ml workspace show -n <workspace> -g <resource-group>
Bash:
az login
az account set -s <subscription-id>
az configure --defaults workspace=<workspace> group=<resource-group> location=<location>
az ml workspace show -n <workspace> -g <resource-group>
PowerShell:
$env:aml_workspace="<workspace>"
$env:aml_resource_group="<resource-group>"
Bash:
export aml_workspace=<workspace>
export aml_resource_group=<resource-group>
This task requires the following:
- Creating a Personal Access Token (PAT) in Github
- Adding a Service Principal (SP) to your forked repository in Github
To create PAT (Personal Access Token), go to Settings of your account, NOT repo setting.
- Go to Settings > Developer Settings > Personal Access Tokens
- Click on Generate new token
- Give it a name and select the following scopes:
Create a Service Principal (SP) in Azure and assign it a role. Replace placeholders with your specific values. This requires contributor permission to the subscription.
az ad sp create-for-rbac --name {REPLACE_SPNAME} --role contributor --scopes /subscriptions/{REPLACE_SUBSCRIPTIONID}/resourceGroups/{REPLACE_RESOURCEGROUPNAME} --sdk-auth
Follow the steps in the link below to create self hosted runners in Github. This is required for the Github Actions to run.
PowerShell:
cd C:\source\repos\amlvision-mlops
Bash:
cd /source/repos/amlvision-mlops
az ml environment create --file ./src/environment/create_aml_env.yml -w $aml_workspace -g $aml_resource_group
az ml data create -f ./src/upload_data/upload.yml -w $aml_workspace -g $aml_resource_group
az ml compute create -f .\src\compute\create-cpu-cluster.yml -w $aml_workspace -g $aml_resource_group
Update the parameters in the create-gpu-cluster.yml file as per your requirement and training data volume.
az ml compute create -f .\src\compute\create-gpu-cluster.yml -w $aml_workspace -g $aml_resource_group
az ml job create -f .\src\dataprep\dataprep.yml -w $aml_workspace -g $aml_resource_group
Update the following parameters in the create_mltable.yml file:
In this step, we convert the coco format dataset to MLTable format. This is required for training using AutoML. This will also create the train and validation MLTable datasets.
Update the following parameters in the create_mltable.yml file.
- training_data_folder_path e.g. azureml://datastores/workspaceblobstore/paths/LocalUpload/8c920d5d5994f81cc82b286c429a1667/training_data/training-mltable-folder/
-
azure_storage_url - Azure Storage url to the images folder. e.g "azureml://subscriptions/840b5c5c-3f4a-459a-94fc-6bad2a969f9d/resourcegroups/ml/workspaces/ws02ent/datastores/workspaceblobstore/paths/LocalUpload/8c920d5d5994f81cc82b286c429a1667/training_data/augmented-samples/images/"
-
output_folder same as training_data_folder_path
-
environment - This is the environment name created in the create environment step. e.g. azureml:mltable_env:1
-
compute - This is the compute name created in the create compute step. e.g. azureml:cpu-cluster
az ml job create -f .\src\create_mltable\create_mltable.yml -w $aml_workspace -g $aml_resource_group
Update path to the MLTable folder in the create_mltable_train_dataset.yml and create_mltable_validation_dataset.yml files.
az ml data create -f .\src\create_mltable\create_mltable_train_dataset.yml -w $aml_workspace -g $aml_resource_group
az ml data create -f .\src\create_mltable\create_mltable_validation_dataset.yml -w $aml_workspace -g $aml_resource_group
Create pipeline job. You can run multiple experiments by changing tile_grid_size to either "5x5" or "9x9" to see if we are able to get better results.
az ml job create -f .\src\training\automl_training_pipeline.yml -w $aml_workspace -g $aml_resource_group
az ml online-endpoint create -f .\src\deployment\endpoint.yml -w $aml_workspace -g $aml_resource_group
az ml online-deployment create -f .\src\deployment\deployment.yml -w $aml_workspace -g $aml_resource_group
Update api-key in the score.py file and run the following command to test the endpoint.
./src/inference/score.py
Result: