Example Image Classification

Deepak Kumar Battini edited this page Nov 13, 2017 · 2 revisions

Example with ImageNet models

Import namespace

using SiaNet;
using SiaNet.Application;
using SiaNet.Common;

Select the device CPU or GPU

GlobalParameters.Device = CNTK.DeviceDescriptor.CPUDevice;

Configure logging (Optional step)

Logging.OnWriteLog += Logging_OnWriteLog;

Declare and load models

string imagePath = "path-to-jpeg-or-png-image";
ImageNet app = new ImageNet(ImageNetModel.ResNet50);
app.LoadModel();

Run prediction

var predictions = app.Predict(imagePath);
foreach (var item in predictions)
{
   Console.WriteLine("Category: {0}, Score: {1}", item.Name, item.Score);
}

Example with Cifar-10 models

Import namespace

using SiaNet.Application;
using SiaNet.Common;

Declare and load models

string imagePath = "path-to-jpeg-or-png-image";
Cifar10 app = new Cifar10(Cifar10Model.ResNet110);
app.LoadModel();

Run prediction

var predictions = app.Predict(imagePath);
foreach (var item in predictions)
{
   Console.WriteLine("Category: {0}, Score: {1}", item.Name, item.Score);
}

Event Functions

private static void Logging_OnWriteLog(string message)
{
    Console.WriteLine("Log: " + message); ;
}
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.