Skip to content

Google's TensorFlow binding for .NET Standard. Developing, training and deploying the Machine Learning models in C#.

License

Notifications You must be signed in to change notification settings

fengge20/TensorFlow.NET

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TensorFlow.NET

TensorFlow.NET (TF.NET) provides a .NET Standard binding for TensorFlow. It aims to implement the complete Tensorflow API in CSharp which allows .NET developers to develop, train and deploy Machine Learning models with the cross-platform .NET Standard framework.

Join the chat at https://gitter.im/publiclab/publiclab Tensorflow.NET codecov NuGet Documentation Status Badge

TF.NET is a member project of SciSharp STACK.

tensors_flowing

Why TensorFlow.NET ?

SciSharp STASK's mission is to bring popular data science technology into the .NET world and to provide .NET developers with a powerful Machine Learning tool set without reinventing the wheel. Scince the APIs are kept as similar as possible you can immediately adapt any existing Tensorflow code in C# with a zero learning curve. Take a look at a comparison picture and see how comfortably a Tensorflow/Python script translates into a C# program with TensorFlow.NET.

pythn vs csharp

SciSharp's philosophy allows a large number of machine learning code written in Python to be quickly migrated to .NET, enabling .NET developers to use cutting edge machine learning models and access a vast number of Tensorflow resources which would not be possible without this project.

In comparison to other projects, like for instance TensorFlowSharp which only provide Tensorflow's low-level C++ API and can only run models that were built using Python, Tensorflow.NET also implements Tensorflow's high level API where all the magic happens. This computation graph building layer is still under active development. Once it is completely implemented you can build new Machine Learning models in C#.

How to use

Install TF.NET through NuGet.

PM> Install-Package TensorFlow.NET

If you are using Linux or Mac OS, please download the pre-compiled dll here and place it in the working folder. This is only need for Linux and Mac OS, and already packed into NuGet for Windows.

Import TF.NET.

using Tensorflow;

Add two constants.

// Create a Constant op
var a = tf.constant(4.0f);
var b = tf.constant(5.0f);
var c = tf.add(a, b);

using (var sess = tf.Session())
{
    var o = sess.run(c);
}

Feed placeholder.

// Create a placeholder op
var a = tf.placeholder(tf.float32);
var b = tf.placeholder(tf.float32);
var c = tf.add(a, b);

using(var sess = tf.Session())
{
    var feed_dict = new Dictionary<Tensor, object>();
    feed_dict.Add(a, 3.0f);
    feed_dict.Add(b, 2.0f);

    var o = sess.run(c, feed_dict);
}

Read the docs & book The Definitive Guide to Tensorflow.NET.

More examples:

Contribute:

Feel like contributing to one of the hottest projects in the Machine Learning field? Want to know how Tensorflow magically creates the computational graph? We appreciate every contribution however small. There are tasks for novices to experts alike, if everyone tackles only a small task the sum of contributions will be huge.

You can:

  • Let everyone know about this project (trivial)
  • Port Tensorflow unit tests from Python to C# (easy)
  • Port missing Tensorflow code from Python to C# (easy)
  • Port Tensorflow examples to C# and raise issues if you come accross missing parts of the API (easy)
  • Debug one of the unit tests that is marked as Ignored to get it to work (can be challenging)
  • Debug one of the not yet working examples and get it to work (hard)

How to debug unit tests:

The best way to find out why a unit test is failing is to single step it in C# and its pendant Python at the same time to see where the flow of execution digresses or where variables exhibit different values. Good Python IDEs like PyCharm let you single step into the tensorflow library code.

Contact

Feel free to star or raise issue on Github.

Join our chat on Gitter or

Scan QR code to join Tencent TIM group:

SciSharp STACK

About

Google's TensorFlow binding for .NET Standard. Developing, training and deploying the Machine Learning models in C#.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 93.2%
  • Python 6.8%