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 https://customvision.ai, 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 = “https://southcentralus.api.cognitive.microsoft.com/customvision/v1.0/Prediction/00e38c62-acfb-4b30-9d04-481b3ea5436b/url?iterationId=ebe48241-a269-4a30-9223-c80d335462ce”
$Key = “51d70eb8f69044dd89408ae4e60b01da”$imageURL = “http://images.all-free-download.com/images/graphicthumb/australian_flag_312448.jpg”
$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
$Result.Predictions
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: https://azure.microsoft.com/en-us/services/cognitive-services/computer-vision/