2

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

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

4

1 回答 1

2

您提到的教程托管的 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

于 2019-02-25T13:49:17.040 回答