3

I'm following the tutorial given by AI School on the sketch2code app (link: https://aischool.microsoft.com/en-us/services/learning-paths/sketch2code/sketch2code-lab/train-an-object-detection-model)

I have pasted my training key into the program.cs file as instructed, and when i run the "dotnet run" command, it gives me the following error:

Unhandled Exception: Microsoft.Rest.HttpOperationException: Operation returned an invalid status code 'Unauthorized' at Microsoft.Azure.CognitiveServices.Vision.CustomVision.Training.TrainingApi.GetDomainsWithHttpMessagesAsync(Dictionary`2 customHeaders, CancellationToken cancellationToken) at Microsoft.Azure.CognitiveServices.Vision.CustomVision.Training.TrainingApiExtensions.GetDomainsAsync(ITrainingApi operations, CancellationToken cancellationToken) at Microsoft.Azure.CognitiveServices.Vision.CustomVision.Training.TrainingApiExtensions.GetDomains(ITrainingApi operations) at Import.Program.Main(String[] args) in C:\Users\DELL_PC\Desktop\BE Project\AISchoolTutorials\sketch2code\Import\Program.cs:line 29

Any help on this?

Harsh Dave
  • 31
  • 2
  • in which region did you create your Custom Vision resource? – Nicolas R Apr 30 '20 at 13:35
  • Hi, i'm getting the same error, i have created Custom Vision resource in US West 2 region, got the key and placed it in Program.cs file, when i run dotnet run command, getting the same error, please help – adarsh May 05 '20 at 16:57

1 Answers1

0

You have to update Microsoft.Azure.CognitiveServices.Vision.CustomVision.Training package.

The solution that worked for me:

  1. Open your terminal and go to the Import folder

  2. Run the following command dotnet add package Microsoft.Azure.CognitiveServices.Vision.CustomVision.Training --version 2.0.0

  3. Open Program.cs and replace this line:

    TrainingApi trainingApi = new TrainingApi() { ApiKey = trainingKey };

    with this line:

    CustomVisionTrainingClient trainingApi = new CustomVisionTrainingClient(new ApiKeyServiceClientCredentials(trainingKey)) {Endpoint = endpoint};

    make sure to replace ENDPOINT with your yours from customvision.ai

Harry
  • 1,021
  • 4
  • 21
  • 41