After you’ve trained an image classification model, you can use the Azure AI Custom Vision SDK to develop a client application that submits new images to be classified.
C#Copy
using System;
using System.IO;
using Microsoft.Azure.CognitiveServices.Vision.CustomVision.Prediction;
// Authenticate a client for the prediction API
CustomVisionPredictionClient prediction_client = new CustomVisionPredictionClient(new ApiKeyServiceClientCredentials("<YOUR_PREDICTION_RESOURCE_KEY>"))
{
Endpoint = "<YOUR_PREDICTION_RESOURCE_ENDPOINT>"
};
// Get classification predictions for an image
MemoryStream image_data = new MemoryStream(File.ReadAllBytes("<PATH_TO_IMAGE_FILE>"));
var result = prediction_client.ClassifyImage("<YOUR_PROJECT_ID>",
"<YOUR_PUBLISHED_MODEL_NAME>",
image_data);
// Process predictions
foreach (var prediction in result.Predictions)
{
if (prediction.Probability > 0.5)
{
Console.WriteLine($"{prediction.TagName} ({prediction.Probability})");
}
}
Leave a Reply