如何从天蓝色获取预测的图像URL?

时间:2019-07-03 11:52:45

标签: python azure microsoft-custom-vision

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

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

如何获取预测的图像URL?

2 个答案:

答案 0 :(得分:0)

您的描述中的API引用链接似乎不正确。如下图所示,有多种版本的Azure Microsoft自定义视觉API,您可以参考https://<your region, such as southcentralus>.dev.cognitive.microsoft.com/docs/services/?page=2来查看它们,用于获取训练图像的API属于训练阶段。

enter image description here

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

图1. Overview标签

enter image description here

图2. Quick start标签,然后单击API reference以查看其与该版本相关的文档

enter image description here

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

enter image description here

这是我的示例代码,用于通过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)

希望有帮助。

答案 1 :(得分:0)

可通过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]