Lab 2 - Train your model
In this lab we are going the train a PyTorch Model that can classify Simpsons using the resources we have created in the previous lab.
1. Connect to your resources
Import dependencies
Start with importing dependencies. If you are using a Notebook in Azure Machine Learning Studio, you have all the latest versions install. If you are running your own Jupyter notebook then you have to install the azureml-sdk (pip install azureml-sdk).
Paste the code below in the first cell and run this cell.
import os, random
import azureml
import shutil
import urllib.request
from pathlib import Path
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import AxesGrid
import cv2
import urllib3
import zipfile
from azureml.core.model import Model, InferenceConfig
from azureml.core import Workspace, Datastore, Experiment, Run, Environment, ScriptRunConfig
from azureml.core.compute import ComputeTarget, AmlCompute, AksCompute, ComputeTarget
from azureml.train.dnn import PyTorch
from azureml.widgets import RunDetails
from azureml.core.webservice import Webservice, AksWebservice, AciWebservice
from azureml.core.dataset import Dataset
from azureml.core.resource_configuration import ResourceConfiguration
from azureml.core.conda_dependencies import CondaDependencies
# check core SDK version number
print("Azure ML SDK Version: ", azureml.core.VERSION)
Connect to workspace
Create a new code cell by clicking on the '+ Code' button
Paste the code below
Run the cell
Performing the interactive authentication using the link and code provide
Run the cell again
It should say: "Connected to workspace: "
Connect to Azure Machine Learning Compute Cluster
Connect to the default datastore

Create an experiment
View your created experiment on: https://ml.azure.com
2. Data
Download the dataset from Github
Unzip the dataset
View your the downloaded dataset: https://ml.azure.com
Choose the refresh button above your folder structure to see data files

Preview the dataset
To take a peak at the images in the dataset paste and the run the code below.

Upload the data to the datastore
Create a dataset from the data in the datastore
Register the dataset
Connect to the dataset
Train the model
Download the training script
Refresh your files and validate that 'train.py' is downloaded in the folder 'trainingscripts': https://ml.azure.com

Submit the PyTorch estimator
Follow the progress of the run
Click on 'View run details' to view all the details of the run under the experiment.

This step can take up to 15 minutes to complete

Register the model

Validate that your model is visible under 'Models': https://ml.azure.com
Download and test your model
Download the model
Download test images
Unzip test images
Run the model over the test images

Last updated
Was this helpful?