TensorFlow 2.x has three mode of graph computation, namely static graph construction (the main method used by TensorFlow 1.x), Eager mode and AutoGraph method. In TensorFlow 2.x, the official recommendation is using the Eager mode and the AutoGraph method.

The Eager mode is convenient for model development and debugging by data scientist, the code is readable and the coding efficiency is high for the machine learning engineers, but the computation performance is not as good as the static computation graph. …


ThensorFlow is capable to handle multiple threads, and queues are powerful mechanism for asynchronous computation. If we have large datasets this can significantly speed up the training process of our models. This functionality is especially handy when reading, pre-processing and extracting in mini-batches our training data. The secret to being able to do professional and high performance training of our model is understanding TensorFlow queuing operations. TensorFlow has implemented 4 types of Queue: FIFOQueue, PaddingFIFOQueue, PriorityQueue and RandomShuffleQueue.

Like everything in TensorFlow, a queue is a node in a computation graph. It’s a stateful node, like a variable: other nodes…


In this article, we’ll implement a simple Convolutional Neural Network model. We’ll implement this model to classify MNIST dataset.

The structure of the neural network we’re going to build is as follows. The hand-written digits images of the MNIST data which has 10 classes (from 0 to 9). The network is with 2 convolutional layers followed by 2 full-connected layers at the end.

neural network architecture

Get started with the implementation:

  1. Prepare data

MNIST is dataset of handwritten digits which contains 55,000 examples for training, 5,000 examples for validation and 10,000 example for testing. The digits have been size-normalized and…


In this article, we’ll learn how to build a graph of neural network model in C#. The key advantage of neural network compared to Linear Classifier is that it can separate data which it not linearly separable. We’ll implement this model to classify hand-written digits images from the MNIST dataset.

The structure of the neural network we’re going to build is as follows. The hand-written digits images of the MNIST data which has 10 classes (from 0 to 9). …


It’s cool we try to run TensorFlow.NET in Jupyter Notebook.

By running SciSharp’s machine learning libraries on Jupyter Notebook, we can easily use .NET to develop and evaluate machine learning models without the need to install a cumbersome .NET development environment. The C# REPL (Read-Evaluate-Print-Loop) mode allows developers to use CSharp just like a scripting language.

To enable Jupyter to run C# REPL mode, we developed a new Jupyter Kernel ICSharpCore that is responsible for the interaction between the Roslyn compiler and the Jupyter Server through the communication layer provided by ZeroMQ.

In the future we will try to run…


Two weeks of hard work, we’re about to complete the conditional statement construction of TensorFlow in C#, Conditional operations are important data flow controls. We have even modified and recompiled the TensorFlow core library written in c++ in order to make the update input operation. Although the code still doesn’t work very well, it has already taken a big step forward.

The incorrect one generated from TensorFlow.NET


I’ll introduce how to training a linear regression model in SciSharp’s TensorFlow.NET.

What is linear regression?

Linear regression is a linear approach to modelling the relationship between a scalar response (or dependent variable) and one or more explanatory variables (or independent variables).

Consider the case of a single variable of interest y and a single predictor variable x. The predictor variables are called by many names: covariates, inputs, features; the predicted variable is often called response, output, outcome.

We have some data $D={x{\tiny i},y{\tiny i}}$ and we assume a simple linear model of this dataset with Gaussian noise:

// Prepare training Data var train_X…


TensorFlow.NET released v0.3 version, let us try to use it for image recognition. An example for using the TensorFlow.NET and NumSharp for image recognition, it will use a pre-trained inception model to predict a image which outputs the categories sorted by probability. The original paper is here. The Inception architecture of GoogLeNet was designed to perform well even under strict constraints on memory and computational budget. The computational cost of Inception is also much lower than other performing successors. …


NumSharp is NumPy port in C# .NET Standard.

After three months of repeated tempering and continuous refactoring, NumSharp has been able to perform a lot of functions, introduced LAPACK’s linear algebra library support, and abstracted into the Provider design, which is scalable from the architectural point of view.

More Unit Tests have been added to ensure quality control during teamwork. An example of a fluid dynamic equation has been added. NDArray supports implicit conversion, which makes it easier to initialize a multidimensional array and supports the creation of scalar ndarray.

After two major refactorings, it took us infinite time and…


We have implemented dozens of commonly used functions for NumSharp, and it is time to start writing machine learning models using NumSharp as a scientific computing library. Today I wrote a simple data generation function and plotted the data view in the .NET environment. You can feel the code written in NumSharp, almost as smooth as NumPy.

NumSharp is the NumPy port in C# .NET Standard

Github: https://github.com/SciSharp/NumSharp

Star me if you like it.

Haiping Chen

Machine Learning Expert

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store