Skip to content

Instantly share code, notes, and snippets.

@elbruno
Created October 9, 2019 19:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elbruno/3e1a389b220a72ee0b7f91f6512b0d27 to your computer and use it in GitHub Desktop.
Save elbruno/3e1a389b220a72ee0b7f91f6512b0d27 to your computer and use it in GitHub Desktop.
CustomVisionEstimationSampleUsage.cs
// open file as byte array
var byteData = GetImageAsByteArray(imageFilePath);
// prediction
var client = new HttpClient();
using var content = new ByteArrayContent(byteData);
content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
var response = await client.PostAsync(Url, content);
var jsonResponse = await response.Content.ReadAsStringAsync();
// Display results
var est = CustomVisionEstimation.FromJson(jsonResponse);
var prediction = est.Predictions.OrderByDescending(x => x.Probability).FirstOrDefault();
Console.WriteLine(@$"{prediction.TagName} - {prediction.Probability}");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment