Krumelur
Krumelur

Reputation: 33058

Azure Custom Vision API returning different results than project portal?

I've create a custom vision project to recognise characters (A, B, C...). What is interesting: if I upload an image of a character (in this case an "N") to the vision API portal it will tell me that it is 99.9% sure it is an "N":

enter image description here

If however I use the client libraries to predict the very same image, I'm getting 53% that it is a "W" and only 37% that it is an "N":

enter image description here

The code to get the prediction on my client:

var client = new CustomVisionPredictionClient()
{
    ApiKey = predictionKey,
    Endpoint = endpoint
};

var result = await client.PredictImageAsync(Guid.Parse(projectId), imageStream).ConfigureAwait(false);
var prediction = result.Predictions.FirstOrDefault();

Where does this difference come from and how to fix because according to the tests I did by uploading images the results are close to 100% correct no matter which character image I upload?

UPDATE: I noticed that there was an update for the client libraries. They went from 0.12pre to 1.0stable. After the update the PredictImageAsync is gone and replaced with DetectImageAsync. This expected as an additional parameter a model name. I tried using the name of the iteration and after a while the method returns with an internal server error. So not sure what to try next.

Upvotes: 0

Views: 747

Answers (1)

Krumelur
Krumelur

Reputation: 33058

The comment above pointed my into the right direction - thanks!

The new client library has got two methods ClassifyImage and DetectImage (and various variations of them) which replace the previously used ones including PredictImage which I was using with the preview version of the client library.

To classify an image (which is what I wanted to do) ClassifyImage should of course be used. The new code looks like this and delivers an almost 100% correct prediction:

var client = new CustomVisionPredictionClient()
{
    ApiKey = predictionKey,
    Endpoint = endpoint
};

var result = await client.ClassifyImageAsync(Guid.Parse(projectId), "Iteration12", imageStream).ConfigureAwait(false);
var prediction = result.Predictions.FirstOrDefault();
  • endpoint is the URL of the region the vision API is hosted in, in my case https://westeurope.api.cognitive.microsoft.com.
  • predictionKey is available on the CustomVision.AI site in your project, so is the projectId
  • The publishedName parameter is the name of the iteration to use (in my case "Iteration12"

Upvotes: 1

Related Questions