【问题标题】:How can I get predicted images URL from azure?如何从 azure 获取预测图像 URL?
【发布时间】:2019-07-12 12:12:47
【问题描述】:

我正在使用 Azure Microsoft 自定义视觉。 我已经创建了我的算法,我现在需要的是我的预测图像的 URL。 我知道我可以使用Training API (get_tagged_images) 中编写的方法获取训练图像,但现在我正在尝试获取预测图像的 URL。在Prediction API 中,没有getter。

如果我在 Azure 自定义视觉门户中检查预测图像,我可以找到 blob URL,但我无法通过方法获取该 URL。

如何获取预测的图片 URL?

【问题讨论】:

    标签: python azure microsoft-custom-vision


    【解决方案1】:

    图像可通过 Training API 中的QueryPredictions API 获得。

    REST 文档是here

    Python 文档是here

    您的代码可能如下所示:

    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]
    

    【讨论】:

      【解决方案2】:

      您描述的API参考链接似乎不正确。 Azure Microsoft Custom Vision API有如下图几个版本,可以参考https://&lt;your region, such as southcentralus&gt;.dev.cognitive.microsoft.com/docs/services/?page=2查看,获取训练图像的API属于训练阶段。

      因此,如果您想获取训练图像的 url,首先您需要了解您现在使用的 Custom Vision Training 的版本。据我所知,您可以在 Azure 门户上订阅的OverviewQuick start 选项卡上查看版本信息。比如我的自定义愿景是1.0,如下图。

      图 1.Overview 选项卡

      图2.Quick start标签,点击API reference查看版本相关文档

      所以我可以看到有三个 API 可以满足您的需求,如下图。

      这是我通过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)
      

      希望对你有帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-09-17
        • 2010-12-20
        • 2020-10-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-01-29
        相关资源
        最近更新 更多