Cognitive Services brings AI within reach of every developer and data scientist. A variety of use cases can be unlocked. All it takes is an API call to embed the ability to see, hear, speak, search, understand, and accelerate advanced decision-making into your apps. Enable developers and data scientists of all skill levels to easily add AI capabilities to their apps.
To get started with Azure Cognitive Services, you'll first need to access the Azure Cloud platform. Below are the steps to get started:
- Sign-Up for an Azure Account
- If you don't have an Azure subscription, you can create an account with Concordia University Account login. Go to the education page to get more than a hundred dollars of free credits.
- Login to Azure Portal
- Go to the Azure Portal and log in using your credentials.
- Navigate to Cognitive Services
- In the left sidebar, scroll down and click on "Create a resource". Then, search for "Cognitive Services" and select it.
- Create a New Service
- Click on the "Create" button to start setting up a new Cognitive Services resource. You'll be prompted to fill in details like:
- Resource Name: A unique name for your service
- Subscription: Choose your Azure subscription, and choose a Student account for free credits.
- Resource Group: Create a new one or select an existing one
- Region: Select the geographical area closest to you or your customers
- Pricing Tier: Choose a pricing tier based on your needs
- Click on the "Create" button to start setting up a new Cognitive Services resource. You'll be prompted to fill in details like:
Azure offers a specialized service for image recognition: Custom Vision on another address instead of Azure Cloud Portal. This service is highly user-friendly and is designed for the rapid and easy creation of custom image classification models.
Differing from the Azure Platform Portal, this Custom Vision can be access by navigating to the Custom Vision Portal.
- Sign In or Sign Up
- If you already have an Azure account, you can sign in.
- Create a New Project
- Click on the "New Project" button and fill in the details for your project, such as the name, description, and the resource you wish to use.
- The type selection is classification, multiclass, and a general domain.
- Upload Images and Annotate
- After creating your project, you must upload images with label to train your model.
- This tutorial provides example data in the “dataset“ folder. This contains a split train dataset and a test dataset. The dataset contains types of Animals. The ImageNet original label is given as the folder name. You are also free to change to the label to the ground-truth name, given in the readme file.
- In another case, when you have too much data and labels, write your own script for uploading images and labels. Please check the Azure Custom Vision official documents using the given APIs to upload data.
- Train the Model
- Once your images are uploaded and annotated, click on the "Train" button to start training your model. Setting the resources as you prefer.
- Evaluate the Model
- After the training is complete, you can see the model's accuracy and other performance metrics.
- Quick Test
- Use the "Quick Test" option to upload an image and quickly check the model's accuracy.
- Publish the Endpoint
- If you are satisfied with your model's performance, click on the "Publish" button to publish your model. During this publishing process, you will need to choose a resource and name your endpoint.
- Get Endpoint and Key
- Once published, you'll receive an Endpoint URL and a key. You can use this information for API calls within your application.
Now that your Custom Vision model has been published and you have your endpoint URL and prediction key, you can start making API calls to classify new images.
Once your Custom Vision model is up and running, testing its API endpoints is crucial for ensuring it works as expected before you integrate it into your application. Below are step-by-step guides for testing your API using both image URLs and image files.
If you have an image URL:
Set Prediction-Key Header to : 12861a3a15xxxxxxxxxxxxxxxxx
Set Content-Type Header to : application/json
Set Body to : {"Url": "https://example.com/image.png"}
If you have an image file:
Set Prediction-Key Header to : 12861a3a1xxxxxxxxxxxxxxxx
Set Content-Type Header to : application/octet-stream
Step 1: Install Required Software
If you haven't already, install Python and the requests library.
pip install requests
Step 2: Prepare Python Script
Create a Python script and add the following code:
import requests
import json
# Endpoint and headers setup
endpoint_url = "https://eastus.api.cognitive.microsoft.com/customvision/v3.0/Prediction/projectname/classify/iterations/imagenetAzure/url"
headers = {
"Prediction-Key": "12861a3a15xxxxxxxxxxxxxxxxx",
"Content-Type": "application/json"
}
# Image URL
payload = json.dumps({"Url": "https://example.com/image.png"})
# API call
response = requests.post(endpoint_url, headers=headers, data=payload)
# Output results
results = response.json()
print(results)
Step 3: Run the Script
Run the Python script. If everything is set up correctly, you should see the predicted labels and confidence scores.
Step 1: Install Required Software
If you haven't already, install Python and the requests library.
pip install requests
Step 2: Prepare Python Script
Create a Python script and add the following code:
import requests
# Endpoint and headers setup
endpoint_url = "https://eastus.api.cognitive.microsoft.com/customvision/v3.0/Prediction/projectname/classify/iterations/imagenetAzure/image"
headers = {
"Prediction-Key": "12861a3a1xxxxxxxxxxxxxxxx",
"Content-Type": "application/octet-stream"
}
# Read the image file
image_path = "path/to/your/image.jpg"
with open(image_path, "rb") as image_data:
# API call
response = requests.post(endpoint_url, headers=headers, data=image_data)
# Output results
results = response.json()
print(results)
Step 3: Run the Script
Run the Python script. If everything is set up correctly, you should see the predicted labels and confidence scores.
Postman is a popular tool for testing APIs. It provides a user-friendly interface to send requests to your API endpoints and view responses. Below is a step-by-step guide to using Postman for testing your Custom Vision API.
- Download and install Postman from here.
Step 1: Open Postman
Open Postman and create a new request by clicking on the New button and then selecting Request.
Step 2: Configure the Request
-
Set the HTTP method to
POST. -
Enter your Custom Vision URL endpoint for image URL classification in the request URL field:
https://eastus.api.cognitive.microsoft.com/customvision/v3.0/Prediction/projectname/classify/iterations/imagenetAzure/url -
In the Headers tab, add the following headers:
Prediction-Key:12861a3a15xxxxxxxxxxxxxxxxxContent-Type:application/json
Step 3: Add Body
Go to the Body tab, select raw and choose JSON from the dropdown. Then enter the following payload:
{
"Url": "https://example.com/image.png"
}
Step 4: Send Request and Review Output
Click the Send button to send the request. You should see the response at the bottom of the Postman window, which will include the predicted labels and their confidence scores.
Step 1: Open Postman
Open Postman and create a new request by clicking on the New button and then selecting Request.
Step 2: Configure the Request
-
Set the HTTP method to
POST. -
Enter your Custom Vision URL endpoint for image file classification in the request URL field:
https://eastus.api.cognitive.microsoft.com/customvision/v3.0/Prediction/projectname/classify/iterations/imagenetAzure/image -
In the Headers tab, add the following headers:
Prediction-Key:12861a3a1xxxxxxxxxxxxxxxxContent-Type:application/octet-stream
Step 3: Add Body
- Go to the
Bodytab. - Select
binary. - Click the
Choose Filesbutton and upload your image file.
Step 4: Send Request and Review Output
Click the Send button to send the request. You should see the response at the bottom of the Postman window, which will include the predicted labels and their confidence scores.
By following these steps, you can ensure your model's API is functioning as expected before integrating it into your application.








