4

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!

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

2 Comments

What does mode = "rb" mean? How many modes are there? I can't seem to find a documentation for this SDK. Thanks!
Here it is a parameter of the open method, see details here: w3schools.com/python/python_file_handling.asp (r = read, b = binary)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.