Microsoft Azure自定义视觉Python SDK-使用计算机中的图像文件进行预测

时间:2019-02-23 08:15:02

标签: azure sdk microsoft-custom-vision

https://docs.microsoft.com/en-us/azure/cognitive-services/custom-vision-service/python-tutorial

我按照上述教程使用了Azure自定义视觉Python SDK。我不想使用互联网上的图像进行预测(如本教程中所示),而是使用计算机中的图像文件。我怎样才能做到这一点?谢谢!

1 个答案:

答案 0 :(得分:0)

Github项目中为您提到的教程提供了一个示例:

这是用于对象检测的,但对于分类的调用是相同的,不同之处在于结果的内容(此处有bounding_box个项,因为对象检测是图像中的预测区域)

def predict_project(prediction_key, project, iteration):
    predictor = CustomVisionPredictionClient(prediction_key, endpoint=ENDPOINT)

    # Open the sample image and get back the prediction results.
    with open(os.path.join(IMAGES_FOLDER, "Test", "test_od_image.jpg"), mode="rb") as test_data:
        results = predictor.predict_image(project.id, test_data, iteration.id)

    # Display the results.
    for prediction in results.predictions:
        print ("\t" + prediction.tag_name + ": {0:.2f}%".format(prediction.probability * 100), prediction.bounding_box.left, prediction.bounding_box.top, prediction.bounding_box.width, prediction.bounding_box.height)

在此处查看资料来源:https://github.com/Azure-Samples/cognitive-services-python-sdk-samples/blob/master/samples/vision/custom_vision_object_detection_sample.py#L122