获取CustomerVisionErrorException:操作返回了无效的状态码“ BadRequest”

时间:2019-05-21 15:07:58

标签: azure image-recognition microsoft-custom-vision

我试图通过使用pickphoto跨媒体提交图像并获得谓词的结果来使用Microsoft.Azure.CognitiveServices.Vision.CustomVision.Prediction功能。我试图将图像作为url或流传递,并不断收到badrequest。我知道我有正确的预测关键字和终点,因为我正在训练,告诉我这是将图像传递到方法中的方式。将图片从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” 期待一个预测。

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

1 个答案:

答案 0 :(得分:0)

在尝试执行一个endpoint.DetectImage(projectId,iteractionName,流)时,我收到了相同的“错误请求消息”。事实是,上周它运行完美。我注意到只有在2 mb左右的大图像时才会发生这种情况