Comment on page
Lab 1 - Train your model
Create a custom vision model using the Microsoft Custom Vision service.
The Custom Vision Endpoint must be created inside a resource group. You can use an existing resource group or create a new one.
To create a new resource group, use the following command. Replace <<resource-group-name>> with your name to use for this resource group. Replace <<location>> with the Azure region to use for this resource group.
az group create --name <resource-group-name> --location <location>
Run the command below to create a free Custom Vision Training Endpoint. Replace <<resource-group-name>> with the name you used above and use the same location. Replace <<name>> with a name for your resource like: my-custom-vision-training.
az cognitiveservices account create --name <name> --kind CustomVision.Training --sku F0 --resource-group <resource-group-name> --location <location> --yes
To get the endpoint from the Cognitive service account run the CLI command below. Replace <<name>> and <<resource-group-name>> with the names used above.
Get the API keys
az cognitiveservices account keys list --name <name> --resource-group <resource-group-name>
Get the endpoint URL
az cognitiveservices account show --name <name> --resource-group <resource-group-name> -o json --query properties.endpoint
- An endpoint URL looking like this: https://<region>.api.cognitive.microsoft.com/
- 2 keys looking like this: 06a611d19f4f4a88a03f3b552a5d2379
For creating the model we are going to use a Jupyter notebook running in Visual Studio Code.
In the terminal type:
code cv.ipynb
This will open a blank notebook in Visual Studio Code.
- A notebook has cells
- In a cells you put code.
- You can run the cell to execute code within that single cell

- In the first cell type:
print("hello world")
- Click on the play button on the left of the cell
- The first time you have to select the Kernel your notebook is using, select the top one.
- The result of the code is displayed below the cell

- To add a new cell you can click the "+code" button in the top menu or if you move your mouse below a cell.
Add every block of code in this lab in a separate cell and excecute the cell as you go.
Every Machine Learning journey starts with a question you want to have answered. For this example, you are going to answer the question: Is it a Homer or a Marge Lego figure.
Now that we know what to ask the model, we can go on to the next requirement; that is data. Our model is going to be a classification model, meaning the model will look at the picture and scores the pictures against the different classes. So, the output will be I’m 70% confident this is Homer and 1% confident that this is Marge. By taking the class with the highest score and setting a minimum threshold for the confidence score we know what is in the picture.
I have created a dataset for you with 50 pictures of a Homer Simpson Lego figure and 50 pictures of a Marge Simpsons Lego figure. I have taken the photos with a few things in mind:
- Used a lot of different backgrounds
- Took the photos from different angles.
- I made sure the only object in the photo was Homer or Marge
- The quality of the photos was consistent.
Use the Python code below to download and extract the dataset to the folder "data-train" or download the dataset and extract it manually in the folder "data-train".
import os
import urllib.request
import zipfile