Gradient for .NET

train neural networks with TensorFlow in C#

Gradient allows you to create, train, and use machine learning models with the full power of TensorFlow API on .NET

var input = tf.placeholder(tf.float32, new TensorShape(null, 1), name: "x");
var output = tf.placeholder(tf.float32, new TensorShape(null, 1), name: "y");
var hiddenLayer = tf.layers.dense(input, hiddenSize,
    activation: tf.sigmoid_fn,
    kernel_initializer: new ones_initializer(),
    bias_initializer: new random_uniform_initializer(minval: -x1, maxval: -x0),
    name: "hidden");
var model = tf.layers.dense(hiddenLayer, units: 1, name: "output");
var cost = tf.losses.mean_squared_error(output, model);
var training = new GradientDescentOptimizer(learning_rate: learningRate).minimize(cost);
Code sample.


  • Access the full set of TensorFlow APIs

    • Build computation graphs, and run them in sessions
    • Use Keras-style high-level APIs
    • Build fast data pipelines, keep logs and model checkpoints
    • Use estimators and the full power of tf.contrib
    • Use eager mode to transform data interactively
    • Many more
  • Train and run models on any hardware platform: CPUs, GPUs, TPUs

  • Use distributed training features

  • Track your training progress with Tensorboard

  • Easily port numerous existing TensorFlow examples

    from simple numerical computation samples to state-of-art models like AlphaZero - the new world's Go champion by DeepMind
  • Get started quickly with a collection of samples

  • Seek help with the growing community

  • Use C# for machine learning

    • Static typing when possible, fallback to dynamic in corner cases
    • IDE support: code completion, documentation hints for classes, functions, and parameters
    • Experimental support for upcoming C# 8.0 features, such as ranges
    • Can be used from C# interactive, and C# kernel for Jupyter
  • Use F# Jupyter notebook to train deep learning models (provided by Azure for free)

    F# Jupyter Notebook screenshot

Comparison with TensorFlowSharp

TensorFlowSharp Gradient
Load TensorFlow models
Train existing models
Create new models with low-level API
Create new models with high-level API
DependenciesTFTF + Python
TensorBoard integration
Dataset manipulation via
Commercial support

Documentation & Tutorials

Get started with an early tech preview, or sign up for Gradient News and Releases.