0

我试图通过使用 pickphoto 跨媒体提交图像并获得预测结果来使用 Microsoft.Azure.CognitiveServices.Vision.CustomVision.Prediction 功能。我试图将图像作为 url 或流传递并不断收到错误请求。我知道我有正确的预测键和端点,因为我从事训练工作,告诉我是我将图像传递给方法的方式。将图像从 Cross Media 挑选照片包转换为

private async void UplodatePictureButton_Clicked(object sender, EventArgs e)
{
    await CrossMedia.Current.Initialize();
    MediaFile file;
    if (!CrossMedia.Current.IsPickPhotoSupported)
    {
        await DisplayAlert("No upload", "Picking a photo is not supported", "OK");
        return;

    }
    file = await CrossMedia.Current.PickPhotoAsync();
    if (file == null)
    {
        return;
    }

    MainImage.Source = ImageSource.FromStream(() =>
    {
        var stream = file.GetStream();

        return stream;
    });


    // Create the Api, passing in the training key
    CustomVisionTrainingClient trainingApi = new CustomVisionTrainingClient()
    {
        ApiKey = trainingKey,
        Endpoint = SouthCentralUsEndpointTraining
    };
    var projects = trainingApi.GetProjects();
    var project = projects.FirstOrDefault(p => p.Name == "Car");
    CustomVisionPredictionClient endpoint = new CustomVisionPredictionClient()
    {
        ApiKey = predictionKey,
        Endpoint = SouthCentralUsEndpointPrediction
    };


    var result = endpoint.ClassifyImageUrl(project.Id, project.Name, new Microsoft.Azure.CognitiveServices.Vision.CustomVision.Prediction.Models.ImageUrl(file.Path));



    foreach (var c in result.Predictions)
    {
        Console.WriteLine($"\t{c.TagName}: {c.Probability:P1}");
    }


}

未处理的异常:Microsoft.Azure.CognitiveService.Vision.CustomerVision.Prediction.Models.CustomVisionErrorException:操作返回了无效的状态代码“BadRequest”期望预测。

这是代码的图片: 代码 这是问题的图片: 问题

4

1 回答 1

2

我在尝试执行端点时收到了相同的“错误请求消息”。DetectImage(projectId,iteractionName,stream)。问题是上周它工作得非常完美。我注意到它只发生在 2 mb 左右的大图像上

于 2019-05-22T12:40:25.387 回答