我正在使用nuget软件包microsoft.azure.cognitiveservices.vision.customvision.prediction
我在自定义视觉门户中创建了自定义视觉应用程序,并获得了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')。
我已经尝试了此示例https://github.com/microsoft/cognitive-customvision-windows/tree/master/master/samples/customvision.sample.sample,使用已折衷的Windows Client,至少确保我的项目信息是正确的,并且我能够访问API。
任何洞察力都将不胜感激
对于.NET客户端SDK,您需要指定基本端点URL ,而无需 。该版本由客户端SDK自动添加。换句话说,您想要(假设Southentalus是您的地区):
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。
如何使用预测API
如果您有图像URL:
您的端点将是这样的
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检查我在类似问题上的其他答案
python自定义视觉预测因子失败
希望它有帮助。