🖍️
Developers Guide to Azure AI
  • Introduction
  • Pre-Requirements
    • Azure Passes
    • Azure CLI
  • Azure Machine Learning
    • Lab 1 - Environment Setup
    • Lab 2 - Train your model
    • Lab 3 - Deploy your model
  • Cognitive Services
    • Lab 1 - Computer Vision
    • Lab 2 - Custom Vision
  • Resources
    • Slides
    • PyTorch Fundamentals
    • Microsoft Learn
Powered by GitBook
On this page
  • 1. Setup the Azure Resources
  • 2. Test the Computer Vision Endpoint
  • 3. Conclusion
  • Resources

Was this helpful?

  1. Cognitive Services

Lab 1 - Computer Vision

Analyze an image by sending it to the Computer Vision API

PreviousLab 3 - Deploy your modelNextLab 2 - Custom Vision

Last updated 3 years ago

Was this helpful?

Microsoft Azure Cognitive Services contain some pre-built models for the most typical tasks, such as object detection in pictures, speech recognition and synthesis, sentiment analysis and so on. Let us test the service to see if it can recognize some specific objects in one particular problem domain.

Suppose we need to create an application that recognizes Simpson Lego Figures:

We will use the from Henk Boelman.

Let us start by looking at how pre-trained can see our images:

1. Setup the Azure Resources

Create a resource group

The Computer 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>

Create the Cognitive Service Account

Run the command below to create a free Computer Vision 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-computervision.

az cognitiveservices account create --name <name> --kind ComputerVision --sku F0 --resource-group <resource-group-name> --location <location> --yes

Get the endpoint details from the Cognitive Service Account

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

At this point you should have:

- An endpoint URL looking like this: https://<region>.api.cognitive.microsoft.com/ - 2 keys looking like this: 06a611d19f4f4a88a03f3b552a5d2379

2. Test the Computer Vision Endpoint

Using the command line

Run the command below to test the endpoint for an image with Bart Simpson on it.

curl -H "Ocp-Apim-Subscription-Key: <<key>>" -H "Content-Type: application/json" "<<endpoint-url>>/vision/v3.2/analyze?visualFeatures=Description" -d "{\"url\":\"https://raw.githubusercontent.com/hnky/dataset-lego-figures/master/_test/Bart.jpg\"}"

The response should look like: { "description":{ "tags":[ "text", "indoor", "toy" ], "captions":[ { "text": "a hand holding a toy", "confidence":0.4660031199455261 }]}}

Using a web interface

Tip: Try it with your own images!

3. Conclusion

In this lab you have created a Computer Vision Endpoint in Azure and send images to the endpoint using the command line and a through a visual interface.

While some of the objects (such as Toy) can be recognized by the pre-trained model, more specialized objects (like this is Bart Simpson or Marge Simpson) are not determined correctly.

Resources

Navigate to: Enter the endpoint URL, the API key, a link to an image and click 'analyze image'. This website shows all the information that comes back from the Computer Vision API.

Computer Vision API
Simpsons Lego Figure Dataset
Computer Vision cognitive service
https://cgntv-cv.azurewebsites.net/
https://azure.microsoft.com/en-us/services/cognitive-services/computer-vision/
https://docs.microsoft.com/en-us/azure/cognitive-services/cognitive-services-apis-create-account-cli?tabs=windows
Continue with lab 2 >