Skip to content
This repository has been archived by the owner on Mar 12, 2020. It is now read-only.

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); ;
}