【问题标题】:Microsoft Azure Custom Vision Python SDK - use image file from computer for predictionMicrosoft Azure Custom Vision Python SDK - 使用计算机中的图像文件进行预测
【发布时间】:2024-01-23 02:37:01
【问题描述】:

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

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

【问题讨论】:

    标签: azure sdk microsoft-custom-vision


    【解决方案1】:

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

    【讨论】:

    最近更新 更多