Hello CNTK from C#

Less than two months ago CNTK 2.2 is released with support of training and evaluating models in C#. For this post we will go through the process of creating  .NET application which has ability to call CNTK. The CNTK library is accessible by using NuGet package.

First,  open Visual Studio and create Classic Windows desktop console application.

Once we have started application, open NuGet package window by right click on Solution item and select “Manage NuGet package for the solution”.

Browse for CNTK and select CNTK.CPUOnly library version, select the project and press install.

Once the installation package is completed, the .NET application can use CNTK library and perform training and evaluation actions. To see the library is available write the flowing code in the main method of the demo application:

var cpu = DeviceDescriptor.UseDefaultDevice();
Console.WriteLine($"Hello from CNTK for {cpu.Type} only!");

Before compile, CNTK project should be changed from Any CPU into x64. This is accomplished by copy the current configuration in to x64.
The flowing picture shows how to do that.

Compile and run the application. The following output should be shown in case the CNTK for C# is successful installed.

Once we have configured the CNTK library to run on .NET platform , we can start building some more interesting NN models.
Stay tuned.


1 thought on “Hello CNTK from C#

  1. Pingback: Train Iris data with MinibatchSource using CNTK and C# | Bahrudin Hrnjica Blog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s