Search code examples
pythonazuremicrosoft-custom-vision

How can I get predicted images URL from azure?


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?


Solution

  • 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]