Microsoft Azure Custom Vision Python SDK - 使用计算机中的图像文件进行预测

Microsoft Azure Custom Vision Python SDK - use image file from computer for prediction

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

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

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