3

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

I followed the above tutorial for using the Azure Custom Vision Python SDK. Instead of using an image on the internet for prediction (as shown in the tutorial), I would like to use an image file from my computer. How can I do that? Thanks!

Mushroom1
  • 33
  • 5

1 Answers1

3

There is a sample in the Github project hosted for the tutorial you mentioned:

It is for Object Detection but the call is the same for Classification, the difference is in the content of the result (here you have bounding_box items because object detection is predicting zones in the image):

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)

See source here: https://github.com/Azure-Samples/cognitive-services-python-sdk-samples/blob/master/samples/vision/custom_vision_object_detection_sample.py#L122

Nicolas R
  • 13,812
  • 2
  • 28
  • 57
  • What does `mode = "rb"` mean? How many modes are there? I can't seem to find a documentation for this SDK. Thanks! – Mushroom1 Feb 26 '19 at 14:38
  • 1
    Here it is a parameter of the `open` method, see details here: https://www.w3schools.com/python/python_file_handling.asp (r = read, b = binary) – Nicolas R Feb 26 '19 at 17:19