我正在使用NuGet软件包Microsoft.Cognitive.CustomVision.Prediction
版本1.2.0
。我创建了一个试验项目,并用一些图像对其进行了训练。现在,当我尝试使用PredicionEndpoint
调用API进行预测时,系统会引发异常:Microsoft.Rest.HttpOperationException
。
当我调试代码并检查异常时,它说:
{"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是图像的正确流,我可以将其输出到项目特定的视图。
调用endpoint.PredictImage(...)
时会引发异常。