2

I'm using the NuGet package Microsoft.Cognitive.CustomVision.Prediction version 1.2.0. I created 1 trial project and trained it with a few images. Now when I try to call the API for a prediction using the PredicionEndpoint, the system throws an exception: Microsoft.Rest.HttpOperationException.

When I debug the code and inspect the exception, it says:

{"Operation returned an invalid status code 'NotFound'"}

This is my code:

var attachmentStream = await httpClient.GetStreamAsync(imageUrl);

PredictionEndpoint endpoint = new PredictionEndpoint() {
 ApiKey = "MY_CORRECT_PREDICTION_KEY"
};

var predictions = new ImagePredictionResultModel();

try {
 predictions = endpoint.PredictImage(new Guid("MY_CORRECT_PROJECT_ID"), attachmentStream);
} catch (Microsoft.Rest.HttpOperationException exception) {
 await context.PostAsync(exception.Body.ToString());
 await context.PostAsync(exception.Data.ToString());
}

foreach(var c in predictions.Predictions) {
  Console.WriteLine($ "{c.Tag}: {c.Probability}");
}

attachmentStream is a correct stream of an image, I am able to output it to a project-specific view.

The exception gets thrown when calling endpoint.PredictImage(...).

Titulum
  • 9,928
  • 11
  • 41
  • 79
  • Perhaps it doesn't like the GUID of the Project ID? Try using the `CustomVision.Training` NuGet package and with that you can get a list of projects. From there they can be filtered by project name. Once you get your project there, you can use the `Id` property for the `PredictImage` call. – Jon Jul 31 '18 at 12:12
  • I tried doing it this way but I get the same result. I also compared the retrieved GUID and the one I used before after but it was the same. – Titulum Jul 31 '18 at 15:11
  • Hmmmes, do you need to use a stream? Would the image URL itself not work? – Jon Jul 31 '18 at 15:12
  • See https://stackoverflow.com/questions/55198000/customvision-api-returns-operation-returned-an-invalid-status-code-notfound – IngoB Aug 03 '19 at 15:59

1 Answers1

2

The issue was that you should mark one of the training interations as default as mentioned in the GithUb issue I created.

Titulum
  • 9,928
  • 11
  • 41
  • 79