![](/img/trans.png)
[英]CustomVision API returns “Operation returned an invalid status code: 'Bad Request'”
[英]CustomVision API returns “Operation returned an invalid status code: 'NotFound'”
我正在使用Nuget包Microsoft.Azure.CognitiveServices.Vision.CustomVision.Prediction
我已经在Custom Vision门户中创建了Custom Vision应用程序,并获得了API密钥和项目ID。
每当我尝试向API发出请求时,总是会引发以下异常:
HttpOperationException:操作返回了无效的状态码'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:操作返回了无效的状态代码:'NotFound' )。
我已经尝试过使用不推荐使用的Windows客户端的示例https://github.com/Microsoft/Cognitive-CustomVision-Windows/tree/master/Samples/CustomVision.Sample ,以至少确保我的项目信息正确并且能够访问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);
CustomVisionPredictionClient
,请注意,除非要微调行为,否则无需将HttpClient
对象传递给CustomVisionPredictionClient
构造函数。
如果您需要更多示例代码,请查看QuickStart 。
如何使用预测API
如果您有图片网址:
您的端点将是这样的
https://southcentralus.api.cognitive.microsoft.com/customvision/v2.0/Prediction/{Project-GUID}/url?iterationId={Iteration-ID}
Set Prediction-Key Header to : predictionId
Set Content-Type Header to : application/json
Set Body to : {"Url": "https://example.com/image.png"}
或者,如果您有图像文件:
端点就像
https://southcentralus.api.cognitive.microsoft.com/customvision/v2.0/Prediction/{ProjectGuid}/image?iterationId={Iteration-Id}
Set Prediction-Key Header to : Predcition-key
Set Content-Type Header to : application/octet-stream
Set Body to : <image file>
请记住,您可以将一个迭代标记为默认值,这样就可以在不指定迭代ID的情况下向其发送数据。 然后,您可以更改应用程序指向的迭代版本,而不必更新应用程序。
使用python检查我对类似问题的其他答案
希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.