Azure Custom Vision API PermissionDenied Error when Using detect_image in Python
I am encountering a PermissionDenied
error when trying to use the detect_image
function of the Azure Custom Vision API in Python, following the documentation: https://learn.microsoft.com/en-us/azure/ai-services/custom-vision-service/quickstarts/object-detection?tabs=windows%2Cvisual-studio&pivots=programming-language-python
The code I have:
with open(os.path.join(base_image_location, "test", "test_image.jpg"), mode="rb") as test_data:
results = predictor.detect_image(project.id, publish_iteration_name, test_data)
for prediction in results.predictions:
print("\t" + prediction.tag_name + ": {0:.2f}% bbox.left = {1:.2f}, bbox.top = {2:.2f}, bbox.width = {3:.2f}, bbox.height = {4:.2f}".format(prediction.probability * 100, prediction.bounding_box.left, prediction.bounding_box.top, prediction.bounding_box.width, prediction.bounding_box.height))
And the error I receive is:
CustomVisionErrorException: Operation returned an invalid status code 'PermissionDenied'
I feel I have used my correct apis/endpoints, wanted to confirm I am getting the right ones though.
I am passing in a key and endpoint from my training model here:
credentials = ApiKeyCredentials(in_headers={"Training-key": training_key})
trainer = CustomVisionTrainingClient(endpoint=endpoint1, credentials=credentials)
Here I am passing in the published models iteration name (from "Published as" in performance from my model).
And the resource id is from my predictive model (from the overarching custom vision settings page)
trainer.publish_iteration(project.id, iteration.id, publish_iteration_name, prediction_resource_id)
Any advice on how I can resolve this? Can also provide more of the code if need be.