本文介绍了CustomVision:操作返回了无效的状态码:'NotFound'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用NuGet包 Microsoft.Cognitive.CustomVision.Prediction 版本 1.2.0 。我创建了1个试用项目,并用一些图像对其进行了训练。现在,当我尝试使用 PredicionEndpoint 调用API进行预测时,系统会引发异常: Microsoft.Rest.HttpOperationException

I'm using the NuGet package Microsoft.Cognitive.CustomVision.Prediction version 1.2.0. I created 1 trial project and trained it with a few images. Now when I try to call the API for a prediction using the PredicionEndpoint, the system throws an exception: Microsoft.Rest.HttpOperationException.

当我调试代码并检查异常时,它说:

When I debug the code and inspect the exception, it says:

{"Operation returned an invalid status code 'NotFound'"}

这是我的代码:

var attachmentStream = await httpClient.GetStreamAsync(imageUrl);

PredictionEndpoint endpoint = new PredictionEndpoint() {
 ApiKey = "MY_CORRECT_PREDICTION_KEY"
};

var predictions = new ImagePredictionResultModel();

try {
 predictions = endpoint.PredictImage(new Guid("MY_CORRECT_PROJECT_ID"), attachmentStream);
} catch (Microsoft.Rest.HttpOperationException exception) {
 await context.PostAsync(exception.Body.ToString());
 await context.PostAsync(exception.Data.ToString());
}

foreach(var c in predictions.Predictions) {
  Console.WriteLine($ "{c.Tag}: {c.Probability}");
}

attachmentStream是正确的图像流,我可以将其输出到

attachmentStream is a correct stream of an image, I am able to output it to a project-specific view.

调用 endpoint.PredictImage(...)时会引发异常。 / p>

The exception gets thrown when calling endpoint.PredictImage(...).

推荐答案

问题是您应将其中一个训练交互标记为默认如所述。

The issue was that you should mark one of the training interations as default as mentioned in the GithUb issue I created.

这篇关于CustomVision:操作返回了无效的状态码:'NotFound'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 18:56