我正在使用 Nuget 包 Microsoft.Azure.CognitiveServices.Vision.CustomVision.Prediction
我已在 Custom Vision 门户中创建了 Custom Vision 应用程序并获取了 API key 和项目 ID。
每当我尝试向 API 发出请求时,总是会抛出以下异常:
HttpOperationException: Operation returned an invalid status code 'NotFound'
这是我的代码:
HttpClient httpClient = new HttpClient();
CustomVisionPredictionClient customVisionPredictionClient = new CustomVisionPredictionClient(httpClient, false)
{
ApiKey = PredictionKey,
Endpoint = PredictionEndpoint,
};
var result = customVisionPredictionClient.PredictImageAsync(CUSTOM_VISION_PROJECT_GUID, imageData);
我尝试了几种不同的端点:
https://southcentralus.api.cognitive.microsoft.com/customvision/v2.0/Prediction https://southcentralus.api.cognitive.microsoft.com/customvision/Prediction/v1.0 https://southcentralus.api.cognitive.microsoft.com/customvision/v1.1/Prediction
虽然在门户上列出的是列表中的第一个。我还成功地将我的应用程序导出到 Azure,这为我提供了列表中的第二个端点,但没有再成功。
我还按照我发现的类似问题 ( CustomVision: Operation returned an invalid status code: 'NotFound' ) 中的建议设置了默认迭代。
我已经尝试过这个示例https://github.com/Microsoft/Cognitive-CustomVision-Windows/tree/master/Samples/CustomVision.Sample它使用已弃用的 Windows 客户端,至少确保我的项目信息正确并且我能够访问 API。
任何见解将不胜感激
最佳答案
对于 .NET 客户端 SDK,您需要指定基本端点 URL, 不指定版本或路径的其余部分。版本由客户端SDK自动添加。换句话说,您需要(假设 SouthCentralUS 是您所在的地区):
PreditionEndpoint = "https://southcentralus.api.cognitive.microsoft.com";
CustomVisionPredictionClient customVisionPredictionClient = new CustomVisionPredictionClient()
{
ApiKey = PredictionKey,
Endpoint = PredictionEndpoint,
};
var result = customVisionPredictionClient.PredictImageAsync(CUSTOM_VISION_PROJECT_GUID, imageData);
顺便说一句,请注意,除非您想微调行为,否则不需要将 HttpClient
对象传递给 CustomVisionPredictionClient
构造函数。
如果您需要更多示例代码,请查看QuickStart .
关于c# - CustomVision API 返回 "Operation returned an invalid status code: ' NotFound'",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55198000/