0

I followed the code mentioned in below link https://github.com/Azure-Samples/cognitive-services-quickstart-code/blob/master/python/CustomVision/ObjectDetection/CustomVisionQuickstart.py

Able to upload images, train model, publish model into customvision.api But when I tried executing the line predictor.detect_image, I am getting below error as CustomVisionErrorException: Operation returned an invalid status code 'Unauthorized'. Please help

1 Answers1

0

But when I tried executing the line predictor.detect_image, I am getting below error as CustomVisionErrorException: Operation returned an invalid status code 'Unauthorized'.

As you haven't provided code to repro the issue, to resolve unauthorized error, based on the available solutions, you can try the following ways:

According to areddish and shawnmittal, make sure to provide correct prediction credentials and endpoint.

  • Check for trained iteration
  • In the project's performance tab, make that trained iteration as default.
TRAINING_ENDPOINT = "TRAINING_RESOURCE_ENDPOINT"
training_key = "TRAINING_RESOURCE_API_KEY"
PREDICTION_ENDPOINT = "PREDICTION_RESOURCE_ENDPOINT"
prediction_key = "PREDICTION_API_KEY"
prediction_resource_id = "PREDICTION_RESOURCE_ID"

credentials = ApiKeyCredentials(in_headers={"Training-key": training_key})
trainer = CustomVisionTrainingClient(TRAINING_ENDPOINT, credentials)
prediction_credentials = ApiKeyCredentials(in_headers={"Prediction-key": prediction_key})
predictor = CustomVisionPredictionClient(PREDICTION_ENDPOINT, prediction_credentials)

You can refer to Operation returned an invalid status code 'unauthorized' on azure cognitive

Ecstasy
  • 1,866
  • 1
  • 9
  • 17
  • Hi @DeepDate-MT, thanks for the info. After running it for 4 times, it started giving expected results on 4th time. Thanks for offering help! – Pavan 0713 Jun 16 '22 at 10:32