Create CIFAR-10 Deep Learning Model With ANNdotNET GUI Tool

With ANNdotNET 1.2 the user is able to create and train deep learning models for image classification. Image classification module provides minimum of GUI actions in order to fully prepare data set. In this post, we are going to create and train deep learning model for CIFAR-10 data set, and see how it easy to do that with ANNdotNET v1.2.

In order to prepare data we have to download CIFAR-10 data set from official web site . The CIFAR-10 data set is provided in 6 binary batch files that should be extracted and persisted on your local machine. Number 10 in the name means that data set is created for 10 labels.The following image shows 10 labels of CIFAR-10 data set each label with few sample images.

CIFAR-10 data set (Learning Multiple Layers of Features from Tiny Images, Alex Krizhevsky, 2009.)

The data set contains 60 000 (50 000 for training and validation, and 10 000 for test) tinny colored images dimensions of 32×32. There is also bigger version of the data set CIFAR-100 with 100 labels. Our task is to create deep learning model capable of recognizing only one of 10 predefined labels from each image.

Data preparation

In order to prepare images, we need to do the following:

The following image shows extracted data set persisted in 10 label folders. The bird folder is opened and shows all images labeled for bird. The test folder contains all images created for testing the model once the model is trained.

In order to properly save all images, we need to create simple C# Console application which should extract and save all 60 000 images. Complete C# program can be downloaded from here.

In order to successfully extract the images, we have to see how those images are stored in binary files. From the official site we can see that there are 5 for training and 1 for test binary files: data_batch_1.bin, data_batch_2.bin, …, data_batch_5.bin, as well as test_batch.bin.

Each of these files is formatted as follows so that the first byte of the array is label index, and the next 3072 bytes represent the image. Each batch contains 10 000 images.

Important to know is that images are stored in CHW format which means that 1d image array is created so that the first 1024 bytes are the red channel values, the next 1024 the green, and the final 1024 the blue. The values are stored in row-major order, so the first 32 bytes are the red channel values of the first row of the image. To end this, all those information have been carried out when implementing the Extractor application. The most important methods are reshaping the 1D byte array into [3, height, width] image tensor, and creating the image from the byte tensor. The following implementation shows how 1D byte array is transformed into 3channel bitmap tensor.

static int[][][] reshape(int channel, int height, int width,  byte[] img)
    var data = new int[channel][][];
    int counter = 0;
    for(int c = 0; c < channel; c++)
        data[c] = new int[height][];
        for (int y = 0; y < height; y++)
            data[c][y] = new int[width];
            for (int x = 0; x < width; x++)
                data[c][y][x] = img[counter];
    return data;

Once the 1D byte array is transformed into tensor, the image can be created and persisted on disk. The following method iterates through all 10000 images in one batch file, extract them and persist on disk.

public static void extractandSave(byte[] batch, string destImgFolder, ref int imgCounter)
    var nStep = 3073;//1 for label and 3072 for image
    for (int i = 0; i < batch.Length; i += nStep)
        var l = (int)batch[i];
        var img = new ArraySegment<byte>(batch, i + 1, nStep - 1).ToArray();
// data in CIFAR-10 dataset is in CHW format, which means CHW: RR...R, GG..G, BB..B;

        // while HWC: RGB, RGB, ... RGB
        var reshaped = reshape(3, 32, 32, img);
        var image = ArrayToImg(reshaped);
        //check if folder exist
        var currentFolder = destImgFolder + classNames[l];

        if (!Directory.Exists(currentFolder))

        //save image to specified folder
        image.Save(currentFolder + "\\" + imgCounter.ToString() + ".png");


Run Cifar-Extractor console application and the process of downloading, extracting and saving images will be finished in few minutes. The most important is that CIFAR-10 data set will be stored in c://sc/datasets/cifar-10 path. This is important later, when we create image classifier.

Now that we have 60000 tiny images on disk arranged by labels we can start creating deep learning model.

Create new image classification project file in ANNdotNET

Open the latest ANNdotNET v1.2 and select New-> Image Classification project. Enter CIFAR project name and press save button. The following image shows CIFAR new ann-project:

Once we have new project, we can start defining image labels by pressing Add button. For each 10 labels we need to add new label item in the list. In each item the following fields should be defined:

  • Image label
  • Path to images with the label.
  • Query – in case we need to get all images within the specified path with certain part of the name. In case all images withing the specified path are images that indicate one label, query should be empty string.

Beside Label item, image transformation should be defined in order to define the size of the images, as well as how many images create validation/test data set.

Assuming the CIFAR-10 data set is extracted at c:/sc/datasets/cifar-10 folder, the following image shows how label items should be defined:

In case label item should be removed from the list, this is done by selecting the item, and then pressing Remove button. Beside image properties, we should defined how many images belong to validation data set. As can be seen 20% of all extracted images will be created validation data set. Notice that images from the test folder are not part of those two data set. they will be used for testing phase once the model is trained. Now that we done with data preparation we can move to the next step: creating mlconifg file.

Create mlconfig in ANNdotNET

By selecting New MLConfig command the new mlconfig file is created within the project explorer. Moreover by pressing F2 key on selected mlconfig tree item, we can easily change the name into “CIRAF-10-ConvNet”. The reason why we gave such name is because we are going to use convolution neural networks.

In order to define mlconfig file we need to define the following:

  • Network configuration using Visual Network Designer
  • Define Learning parameters
  • Define training parameters

Create Network configuration

By using Visual Network Designer (VND) we can quickly create network model. For this CIFAR-10 data set we are going to create 11 layers model with 4 Constitutional, 2 Pooling, 1 DropOut and 3 Dense layer, all followed by Scale layer:

Scale (1/255)->Conv2D(32,[3,3])->Conv2D(32,[3,3])->Pooling2d([2,2],2)->Conv2D(64,[3,3])->Conv2D(64,[3,3])->Pooling2d([2,2],2)->DropOut(0.5)->Dense(64, TanH)->Dense(32, TanH)->Dense(10,Softmax)

This network can be created so that we select appropriate layer from the VND combo box and click on Add button. The first layer is Scale layer, since we need to normalize the input values to be in interval (0,1). Then we created two sequence of Convolution, Pooling layers. Once we done with that, we can add two Dense layers with 64 and 32 neurons with TanH activation function. The last layer is output layer that must follow the output dimension, and Softmax activation function.

Once network model is defined, we can move to the next step: Setting learning and training parameters.

Learning parameters can be defined through the Learning parameters interface: For this model we can select:

  • AdamLearner with 0.005 rate and 0.9 momentum value. Loss function is Classification Error, and the evaluation function is Classification Accuracy

In order to define the training parameters we switch to Training tab page and setup:

  • Number of epoch
  • Minibatch size
  • Progress frequency
  • Randomize minibatch during training

Now we have enough information to start model training. The training process is started by selecting Run command from the application ribbon. In order to get good model we need to train the model at least few thousands epoch. The following image shows trained model with training history charts.

The model is trained with exactly of 4071 epochs, with network parameters mentioned above. As can be seen from the upper chart, mini-batch loss function was CrossEntropyWithSoftmax, while the evaluation function was classification accuracy.  The bottom chart shows performance of the training and validation data sets for each 4071 epoch. We can also recognize that validation data set has roughly the same accuracy as training data set which indicates the model is trained well.  More details about model performance can be seen on the next image:

Upper charts of the image above show actual and predicted values for training (left) and validation (right). Most of the point values are blue and overlap the orange which indicates that most of value are correctly predicted. The charts can be zoomed and view details of each value.The bottom part of the evaluation show performance parameters of the model for corresponded data set. As can be seen the trained model has 0.91 overall accuracy for training data set and 0.826 overall accuracy for validation data set, which indicate pretty good accuracy of the model. Moreover, the next two images shows confusion matrix for the both data sets, which in details shows how model predict all 10 labels.

The last part of the post is testing model for test data set. For that purpose we selected 10 random images from each label of the test set, and evaluate the model. The following images shows the model correctly predicted all 10 images.


ANNdotNET v1.2 image classification module offers complete data preparation and model development for image classification. The user can prepare data for training, create network model with Neural Network Designer, and perform set of statistical tools against trained model in order to validate and evaluate model. The important note is that the data set of images must be stored on specific location in order to use this trained model shown in the blog post. The trained model, as well as mlcofig files, can be load directly into ANNdotNET project explorer by doublick on feed example.

ANNdotNET as open source project provides outstanding way in complete development of deep learning model.

ANNdotNET v1.2 has been released

With the new year, the new version of ANNdotNET has come. This is mayor updates which brings very exciting features.

Here are what has come with the ANNdotNET v1.2:

Image classification module:- this is the main update to this version. Previously you could run image processing only when you manually create mlconfig file, with text based reader. Now you can perform full image preparation prior to create mlconfig file. For example Cat&Dog image processing deep learning example is provided and can be found at ANNdotNET Start page. Notice: prior to run this example you should download image dataset from Kaggle web site and save it on specific location on you disk. More information can be found at ProjectInfo tab (see image below).

ANNdotNET Feed: brings ability to share interesting annproject‘s to all community. Once the interesting project is added to ANNdotNET Feed it can be viewed by all uses that have installed ANNdotNET v1.2+ version. Currently three examples are provided through ANNdotNET Feed.

Other improvements

  • Time Series Generator – previously time series could be loaded in Data Import dialog only with one column data without header. Now, more than one column with header can be imported, and only the last one will be generated as time series, while the rest columns will remain as are.
  • Split Raw Data Set to: train, validation and test sets. Up to now the user could split raw data set on train and validation sets only.
  • Export to Excel with all three data sets. In case test data set is defined, Export to Excel will also export data set for testing.
  • Optimization data loading and handling with huge data set.There are some improvements in loading huge data set.
  • Visual Network Designer improvements. Visual Network Designer now is provided by more options.
  • Added new Layer types: Convolution, Pooling, etc.
  • Insert button Insert Layer in the network at specific position.

Raw data set can be split on validation and test set.
Improvements in Visual Network Designer

Bug Fixes

  • Some WinForms Dialogs has been converted into WPF based windows in order to fix WInForm DPI issue on scalled monitors. #42
  • Minor code improvements and bug fixes

In case you like this project, go to and download the latest version, and dont forget to give a star.

How to prepare machine with GPU for Deep Learning with CNTK, TensorFlow and Keras

In this blog post, step by step instruction is going to be described in order to prepare clean Windows based machine (virtual) with GPU for deep learning with CNTK, Tensorflow and Keras. Installation of OS is not covered in the post, and this is task is assumed it is already completed.

Preparing the machine

Once you have up and running clean Windows machine, there are several things you should concider:

1. Physical machine with NVIDIA compatible graphics card.
This requirement will provide deep learning frameworks to train models on GPU, which speedups the training process rapidly.

2. Virtual Machine with GPU.
In case you plan to prepare virtual machine, or Azure virtual machine, be aware that (for my knowledge) only Windows Server 2016 based virtual machine recognize GPU card. So if you install Windows 10 or lower version on virtual machine, you will not be able to use GPU for training deep learning models.

3. Azure N-Series VM
In case you plan to select one of Azure virtual machine, only N-series support GPU.

Installation for NVIDIA driver and related stuff

In this blog post only NVIDIA related driver will be described, and no other installation driver will be considered. In case of other driver installation, please refer to related vendor site.

For this blog post, drivers and related stuff for NVIDIA Tesla K80 graphics card will be explained. For other NVIDIA cards the installation process is almost the same.

1. First you have to know what NVIDIA graphics card is installed your machine.

2. Then go to NVIDIA official site, and select appropriate information before driver download. In my case the following information are selected:

3. Press search and download the driver.

Once you download the driver, install it on your machine.

Once you have driver installed, you have to download and install two more NVIDIA software components:

1. CUDA Toolkit 9.0
2. cuDNN 7.4

Those two software components are used by deep learning frameworks (CNTK and TensorFlow) for GPU based computation.
The CUDA 9.0 is compatible with the latest versions of CNTK 2.6 and Tensorflow 1.12, so it makes easier to used one CUDA version for both frameworks, which was not the case in the past.

Installation of CUDA 9.0

In order to install CUDA Toolkit, go to CUDA download page and select appropriate information of your machine. The following information I have selected in order to download it:

Once you select the right information, press download button. Once the CUDA 9.0 is downloaded on you machine install it by performing Express installation option.

Installation of cuDNN 7.4

Download the cuDNN from the official site, and then press Download cuDNN button.

Once you press it, the following page should appear. Notice also notice that login page might appear before download page.

Once the cuDNN is downloaded unzip it. Only three files are exist in the installation, and those should be copied on the right place. In order to successfully install cuDNN, perform the following files copy:

1. cudnn64_7.dll to C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin

2. cudnn.lib to C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\lib\x64

3. cudnn.h to C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\include

Once you’ve done that, the NVIDIA related stuff installation has been completed, and you can switch to installation Python related stuff.

Installation Python development environment

CNTK and TensorFlow support various python environments, but you should always see official site for the compatibility. In order to use CNTK and Tensor flow on the same python environment, it is recommended to use Anaconda3 version 4.1.1 environment.

First download the Anaconda3 v4.1.1 from the official site:

– Go to and download Anacoda3 4.1.1 for 64 bit.

Once the Anaconda is downloaded install it, on standard way using installer.

Prepare python environment for the installation

Once Anaconda3 4.1.1 has been installed several commands needs to be performed in order to install all necessary software. Before start, we need to upgrade pip since Anaconda3 4.1.1 is little bit old. So run the Anaconda Command Prompt from the Start->Anacoda->Anaconda Prompt

Once the Anaconda Prompt is running, type the following command:

python -m pip install --upgrade pip

Now we are ready to install CNTK, Tensorflow and Keras. But before that we should create separate python environment with python 3.5. Once we have the environment we can install those frameworks to it. The new environment must be relies on python 3.5. So type the following command into Anaconda Prompt:

conda create --name mlenv1218 python=3.5

We have created environment named “mlenv1218“. Now don’t forget to activate the environment before installing software. Type the following commands in order to activate environment.

activate mlenv1218

Once we’ve done that, the Anaconda Prompt should looks like (active environment is shown on the left site):

Installation of CNTK, Tensorflow and Keras

It is very important to properly install NVIDIA related stuff, before installation of deep learning libraries, because most of the installation problems are related to it. Once we have NVIDIA and Python environment installed properly, the installation process for deep learning frameworks is very easy.
In Anaconda Prompt, with activate “mlenv2118” environment, type the following command in order to install CNTK:

pip install cntk-gpu

The type the following python code to test CNTK installation:

python -c "import cntk; print(cntk.__version__)"

Once you’ve done that, type the following command in order to install Tensorflow:

pip install tensorflow-gpu

Type the following command in order to test installation:

python -c "import tensorflow as tf; tf.enable_eager_execution(); print(tf.reduce_sum(tf.random_normal([1000, 1000])))"

At the end type the following command to install Keras:

pip install keras

In addition it is useful to install the following packages:

  • matplotlib
  • opencv
  • scikit-learn
  • numpy

Those packages are installed using:

pip install matplotlib, and
pip install opencv-python
pip install scikit-learn
pip install numpy

That is all to install in order to run CNTK, TensorFlow and Keras.

Install Visual Studio Code to write python code

In order to write python code for deep learning you have two options among many other:

  • Install Visual Studio 2017
  • Install Visual Studio Code

Visual Studio Code can be downloaded from official site. Download it and install. Once you install the VS Code, run it. Press Extension button on the lest side and type python in search box. Select on Python extension and press Install.

  • Restart VS Code, and
  • Select File->New File
  • Save file as
  • Change current python environment to “mlenv1218” (by double click)
  • Run python code, by right click on python code and select “Run Python File in Terminal
import cntk 
import tensorflow as tf
import keras

the following output produced the above code:

CNTK on .NET platform – my session at ATD 14

Advanced Technology Days 14, ATD14, is a two days conference organized by the Microsoft and MS Community in Zagreb the Capital of Croatia. My session about Microsoft Cognitive Toolkit, CNTK on .NET platform held on second day, and I was very happy to talk about this, since only two months ago .NET Core support has finally implemented in the library.

There were more demos that I had time to preset them, so at the end of this blog you can find link for all demos and presentation file. Also the information about data sets need to be downloaded prior to run examples are placed in the code.
The last demo about ANNdotNET you can find on
The demos and presentation file can be found at this location:!AgPZDj-_uxGLhY1pCCODeT03qK_T3A

See you next time,

How to visualize CNTK network in C#

When building deep learning models, it is often required to check the model for consistency and proper parameters definition. In ANNdotNET, ml network models are designed using Visual Network Designer (VND), so it is easy to see the network configuration. Beside VND, in ANNdotNET there are several visualization features on different level: network preparation, model training phase, post training evaluation, performance analysis, and export results. In this blog post we will learn how to use those features when working with deep learning models

Visualization during network preparation and model training

When preparing network and training parameters, we need information about data sets, input format and output type. This information is relevant for selecting what type of network model to configure, what types of layers we will use, and what learner to select. For example the flowing image shows  network configuration containing of 2 embedding layers, 3 dense layers and 2 dropout layers. This network configuration is used to train CNTK model for mushroom data set. As can be seen network layers are arranged as listbox items, and the user has possibility to see, on the highest level, how neural networks looks like, which layers are included in the network, and how many dimensions each layer is defined. This is very helpful, since it provides the way of building network very quickly and accurately, and it requires much less times in comparisons to use traditional way of coding the network in python, or other programming language.

Image 1: ANNdotNET Network Settings 

ANNdotNET Network Settings page provides pretty much information about the network, input and output layers, what data set are defined, as well as whole network configuration arranged in layers. Beside network related information, the Network Settings tab page also provides the learning parameters for the network training. More about Visual Network Designer the ready can find on one of the previous blog post.

Since ANNdotNET implements MLEngine which is based on CNTK, so all CNTK related visualization features could be used. The CNTK  library provides rich set of visualizations. For example you can use Tensorboard in CNTK  for visualization not just computational graph, but also training history, model evaluation etc. Beside Tensorboard, CNTK provides logger module which uses Graphviz tool for visualizing network graph. The bad news of this is that all above features cannot be run on C#, since those implementation are available only in python.

This is one of the main reason why ANNdotNET provides rich set of visualizations for .NET platform. This includes: training history, model evaluation for training and validation data set, as well as model performance analysis. The following image show some of the visualization features: the training history (loss and evaluation) of minibatches during training of mushroom model:

Moreover, the following image shows evaluation of training and validation set for each iteration during training:

Those graphs are generated during training phase, so the user can see what is happening with the model.  This is of tremendous help, when deciding when to stop the training process, or are training parameters produce good model at all, or this can be helpful in case when can stop and change parameters values. In case we need to stop the training process immediately, ANNdotNET provides Stop command which stops training process at any time.

Model performance visualization

Once the model is trained, ANNdotNET provides performance analysis tool for all three types of ML problems: regression, binary and multi class classification.

Since the mushrooms project is binary ML problem the following image shows the performance of the trained model:

Using Graphviz to visualize CNTK network graph in C#

We have seen that ANNdotNET provides all types of visualizations CNTK models, and those features are provided by mouse click through the GUI interfaces. One more feature are coming to ANNdotNET v1.1 which uses Grpahviz to visualize CNTK network graph. The feature is implemented based on original CNTK python implementation with some modification and style.

In order to use Graphviz to visualize network computation graph the following requirements must be met:

  • Install Graphviz on you machine.
  • Register Graphviz path as system variable. (See image below)

Now that you have install Graphviz tool, you can generate nice image of your network model directly in ANNdotNET just by click on Graph button above the Visual Network Designer (see image 1).

Here is some of nice graphs which can be generate from ANNdotNET preclaculated models.

Graphviz generated graph of mushrooms model implemented in ANNdotNET

In case you like this nice visualization features go to, download the latest version from release section or just download the source code and try it with Visual Studio, but don’t forget to give a star.

Star ANNdotNET project if you found it useful.

In the next blog post I will show you how visualization of CNTK computational graph is implemented, so you will be able to use it in your custom solutions.

ANNdotNET v1.1 has been release


ANNdotNET –  is an open source project for deep learning written in C# for developing and training deep learning models. The project is based on Microsoft CNTK (CogNitive ToolKit) Microsoft open source library for deep learning. It is supposed to be higher API for deep learning in .NET, but also provides, data preparation and transformation from
rawDataSet  into mlready dataset, monitoring the training process with additional evaluation functions, capability of early stopping during training, model evaluation and validation, exporting and deployment options.

The process of creating, training, evaluating and exporting models is provided from the GUI Application and does not require knowledge for supported programming languages.

The ANNdotNET is ideal in several scenarios when user want:

  • more focus on neural network development and training process using on classic desktop approach, instead of focusing on coding,
  • less time spending on debugging source code and peripheral tasks like installing and updating packages, debugging errors in the code, and more focusing on different configuration and parameter variants,
  • to model and is not familiar with supported programming languages,

In case the problem requires more advanced custom models, or training process, ANNdotNET CMD provides high level of API for such implementation. All ml configurations developed with GUI tool, can be handled with CMD tool and vice versa.

To get quick introduction to the tool, there are dozens of pre-calculated projects included in the installer which can be opened from the Start page as well as from CMD tool. The projects are based on famous datasets freely distributed on repositories from several categories: regression, binary and multi-class classification problems, image classifications, times series, etc.

This version brings upgrade of Machine Learning Engine and set of minor bug fixes identified in the application.

The following enhancements has been made in this release

  • The ANNdotNET MLEngine now relies on CNTK 2.6.
  • Information about data sets has been added to Network Page
  • Chart controls on Training and Evaluation pages are simplified and improved visibility.
  • Refresh button has been removed and added automatic model evaluation.

Bug Fixes

  • Test Tab Page had bug which add new rows whenever the user press Evaluate button.

ANNdotNET v1.1 can be downloaded from the Github page at For full list of features you can see release note file at:

Export options in ANNdotNET

ANNdotNET v1.0 has been release a few weeks ago, and the feedback is very positive. Also up to now there is no any blocking or serious bug in the release which makes me very happy. For this blog post we are going through Export options in ANNdotNET.

The ANNdotNET supposed to be an application which can offer whole life-cycle for  machine learning project: from the defining raw data set, cleaning and features engineering, to training and evaluation of the model. Also with different mlconfig files within the same project, the user has ability to create as many ml configurations as wants. Once the user select the best ml configuration, and the training and evaluation process completes, the next step in ML project life-cycle is the model deployment/export.

Currently, ANNdotNET defines three export options:

  • Export model result to CSV file,
  • Export model and model result to Excel, and
  • Export model in CNTK file format.

With those three export option, we can achieve many ML scenarios.

Export to CSV

Export to CSV provides exporting actual and predicted values of testing data set to comma separated txt file. In case the testing data set is not provided, the result of validation data set will exported. In case nor testing nor validation dataset are not provided the export process is terminated.

The export process starts by selecting appropriate mlconfig file. The network model must be trained prior to be exported.

2018-10-22_9-35-07.pngOnce the export process completes, the csv file is created on disk. We can import the exported result in Excel, and similar content will be shows as image below:


Exported result is shows in two columns. The actual and predicted values. In case the classification result is exported, in the header the information about class values are exported.

Export to Excel

Export to Excel option is more than just exporting the result. In fact, it is deployment of the model into Excel environment. Beside exporting all defined data sets (training, Validation, and Test) the model is also exported. Predicted values are calculated by using ANNdotNET Excel Add-in, which the model evaluation looks like calling ordinary Excel formula.  More information how it works can be found here.


Exported xlsx file can be opened, and the further analysis for the model and related data sets can be continued. The following image shows exported model for Concrete Slum Test example. Since only two data sets are defined (training and validation) those data sets are exported. As can be seen the predicted column is not filled, only the row is filled with the formula that must be evaluated by inserting equal sign “=” in front of the formula.


Once the formula is evaluated for the first row, we can use Excel trick to copy it on other rows.

The same situation is for other data sets separated in Excel Worksheets.

Export to CNTK

The last option allows to export CNTK trained model in CNTK format. Also ONNX format will be supported as soon as being available on CNTK for C# library. This option is handy in situation where trained CNTK model being evaluated in other solutions.

For this blog post, there is a short video which the reader can see all three options in actions.