0

I'm using Azure Microsoft Custom Vision. I've already created my algorithm, and what I need now is the URL of my predicted images. I'm aware that I can get the training images with methods written in Training API (get_tagged_images), but now I'm trying to get the URL of the prediction image. In the Prediction API, there are no getters.

If I inspect the predicted image in Azure Custom Vision Portal, I can find the blob URL, but I'm unable to get that URL through a method.

How can I get the predicted image URL?

polaupa
  • 149
  • 11

2 Answers2

0

It seems that the links of API references in your description are not correct. And there are several versions of Azure Microsoft Custom Vision APIs as the figure below, you can refer to https://<your region, such as southcentralus>.dev.cognitive.microsoft.com/docs/services/?page=2 to see them, and the APIs for getting training images are belong to training stage.

enter image description here

So if you want to get the urls of the training images, first you need to find out what version of Custom Vision Training you used now. As I know, you can see the version information at the Overview & Quick start tabs of your subscription on Azure portal. For example, my custom vision is 1.0 as the figures below.

Fig 1. Overview tab

enter image description here

Fig 2. Quick start tab, and click the API reference to see its documents related to the version

enter image description here

So I can see there are three APIs satisfied your needs, as the figure below.

enter image description here

Here is my sample code to list all tagged images via GetAllTaggedImages(v1.0).

import requests

projectId = "<your project id from project settings of Cognitive portal>"
endpoint = f"https://southcentralus.api.cognitive.microsoft.com/customvision/v1.0/Training/projects/{projectId}/images/tagged/all"
print(endpoint)

headers = {
    'Training-key': '<key from keys tab of Azure portal or project settings of Cognitive portal>',
}

resp = requests.get(endpoint, headers=headers)
print(resp.text)

import json
images = json.loads(resp.text)
image_urls = (image['ImageUri'] for image in images)
for image_url in image_urls:
    print(image_url)

Hope it helps.

Peter Pan
  • 23,476
  • 4
  • 25
  • 43
0

The images are available through the QueryPredictions API in the Training API.

The REST documentation is here.

The Python documentation is here.

Here's what your code might look like:

from azure.cognitiveservices.vision.customvision.training import CustomVisionTrainingClient
from azure.cognitiveservices.vision.customvision.training.models import PredictionQueryToken

# Set your region
endpoint = 'https://<your region>.api.cognitive.microsoft.com'

# Set your Training API key
training_key = '<your training key>'

# Set your Project ID
project_id = '<your project id>'

# Query the stored prediction images
trainer = CustomVisionTrainingClient(training_key, endpoint=endpoint)
token = PredictionQueryToken()
response = trainer.query_predictions(project_id, token)

# Get the image URLs, for example
urls = [result.original_image_uri for result in response.results]
cthrash
  • 2,938
  • 2
  • 11
  • 10