Custom Vision with PowerShell

Custom Vision is service for creating computer vision models that can be interacted with via a REST API. Custom Vision is powered by Cognitive Services.

Here is a simple demo using PowerShell to determine whether a flag is from New Zealand or Australia. These flags have a lot of similarities, including the Union Jack, blue back ground and Stars, so I thought it would be a good test of the technology.

The first task is to create a project on, upload images of flags and train the model. In this case I have added two tags, New Zealand and Australia. The minimum number of photos per tag is 5. Choose a variety of angles and shapes.


Once the images have been uploaded, choose Train from the menu to build the model.

Next, you will need to get the API URL and Prediction Key from the Performance tab.


Now for the PowerShell bit. In this example, we call the Prediction API with the URL to a flag image.

Replace the customVisionAPIURI and Key with the values from your model. Replace the ImageURL with the URL of a flag.

$CustomVisionAPIURI = “”
$Key = “51d70eb8f69044dd89408ae4e60b01da”

$imageURL = “”

$bod = @{url = $imageUrl };
$jsbod = ConvertTo-Json $bod
$Result = Invoke-RestMethod -Method Post -Uri $CustomVisionAPIURI -Header @{ “Prediction-Key” = $Key } -Body $jsbod -ContentType “application/json” -ErrorAction Stop

The results from the script:

TagId Tag Probability
—– — ———–
61740b10-a791-43a9-b6ae-edd2559431a8 Australia 1.0
3ecac738-a7d8-451d-98b9-7d5b36b20add New Zealand 1.67903181E-07

That’s it!

A practical application of this technology could be classifying photos in SharePoint. The script could be extended to run across a library of photos and populate data into a metadata column to classify the image. For example a library containing photos of different types of cattle, could be processed to determine if they are Angus, Jersey, Friesian, Hereford etc.

There are many more advanced applications of Cognitive Services such as medical image analysis, quality processes, identifying faces etc.

More technical detail on CustomVision API can be found here:



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s