CustomVision API 返回“操作返回无效状态代码:'NotFound'”

Tot*_*oto 1 c# azure azure-cognitive-services microsoft-custom-vision

我正在使用 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);        
Run Code Online (Sandbox Code Playgroud)

我尝试了几个不同的端点:

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 returns an invalid status code: 'NotFound')。

我已经尝试过这个示例https://github.com/Microsoft/Cognitive-CustomVision-Windows/tree/master/Samples/CustomVision.Sample它使用不推荐使用的 Windows 客户端,至少确保我的项目信息是正确的,我能够访问 API。

任何见解将不胜感激

小智 6

对于 .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);
Run Code Online (Sandbox Code Playgroud)

顺便说一句,请注意,除非您想微调行为,否则不需要将HttpClient对象传递给CustomVisionPredictionClient构造函数。

如果您需要更多示例代码,请查看QuickStart