操作返回了无效的状态码“未经授权”,将训练图像上传到自定义视觉

时间:2020-07-10 10:32:35

标签: c# azure microsoft-custom-vision

我正在尝试完成AI School https://aischool.microsoft.com/en-us/services/learning-paths/sketch2code/sketch2code-lab/train-an-object-detection-model

的此sketch2code教程

教程的第9步说:

输入运行命令dotnet,然后按Enter键。

我正在使用Visual Studio 2019可能是问题所在吗?

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 cancellatio
nToken)
   at Microsoft.Azure.CognitiveServices.Vision.CustomVision.Training.TrainingApiExtensions.GetDomains(ITrainingApi operations)
   at Import.Program.Main(String[] args) in C:\Users\Harry\Downloads\AISchoolTutorials\sketch2code\Import\Program.cs:line 29

1 个答案:

答案 0 :(得分:0)

您必须更新Microsoft.Azure.CognitiveServices.Vision.CustomVision.Training程序包。

  1. 打开您的终端并转到“导入”文件夹

  2. 运行以下命令dotnet add package Microsoft.Azure.CognitiveServices.Vision.CustomVision.Training --version 2.0.0

  3. 打开Program.cs并替换以下行:

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

    有这行:

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

    请确保使用customvision.ai

    中的ENDPOINT替换您的ENDPOINT