microsoft / Cognitive-CustomVision-Windows

Custom Vision Client Library and Sample for Windows
MIT License
67 stars 60 forks source link

Operation returned an invalid status code: 'NotFound' #19

Closed artus closed 6 years ago

artus commented 6 years ago

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(...).

chsienki commented 6 years ago

You probably don't have a 'default' iteration, meaning you'll need to either pass an explicit iteration ID to PredictImage, or assign an iteration to be the default by clicking 'Make default' in the Performance tab.

ericbrunner commented 6 years ago

@artus I would apply your setting / keys to that sample locally and compare whats wrong in your code.https://github.com/Microsoft/Cognitive-CustomVision-Windows/tree/master/Samples/CustomVision.Sample

artus commented 6 years ago

The solution @chsienki provided was the correct one. I marked one of my iterations as "default" and it worked like a charm. Thank you for helping me! Maybe this information should be included in the HTTP response?