All Projects → SciSharp → Tensorflow.net

SciSharp / Tensorflow.net

Licence: apache-2.0
.NET Standard bindings for Google's TensorFlow for developing, training and deploying Machine Learning models in C# and F#.

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to Tensorflow.net

Cskefu
🌲 春松客服,智能客服系统,开源客服系统 ,机器人客服,客服系统开发框架,多渠道
Stars: ✭ 1,970 (-9.96%)
Mutual labels:  chatbot
Magento Chatbot
Magento Chatbot Integration with Telegram, Messenger, Whatsapp, WeChat, Skype and wit.ai.
Stars: ✭ 149 (-93.19%)
Mutual labels:  chatbot
Mailbody
Create transactional email with a fluent interface (.net)
Stars: ✭ 151 (-93.1%)
Mutual labels:  dotnetcore
Caiss
跨平台/多语言的 相似向量/相似词/相似句 高性能检索引擎。功能强大,使用方便。欢迎star & fork。Build together! Power another !
Stars: ✭ 142 (-93.51%)
Mutual labels:  chatbot
Dotnetcore.samples
.NET Core Samples - Code it Yourself...
Stars: ✭ 147 (-93.28%)
Mutual labels:  dotnetcore
Netbarcode
Barcode generation library written in C# and .NET Standard 2
Stars: ✭ 149 (-93.19%)
Mutual labels:  dotnetcore
Convform
A jQuery plugin that transforms a form into an interactive chat.
Stars: ✭ 141 (-93.56%)
Mutual labels:  chatbot
Mmalsharp
C# wrapper to Broadcom's MMAL with an API to the Raspberry Pi camera.
Stars: ✭ 152 (-93.05%)
Mutual labels:  dotnetcore
Go Bot Drl
Goal-Oriented Chatbot trained with Deep Reinforcement Learning
Stars: ✭ 149 (-93.19%)
Mutual labels:  chatbot
Data
Fast DB-independent DAL for .NET Core: abstract queries, SQL commands builder, schema-less data access, POCO mapping (micro-ORM).
Stars: ✭ 150 (-93.14%)
Mutual labels:  dotnetcore
Seq2seq chatbot new
基于seq2seq模型的简单对话系统的tf实现,具有embedding、attention、beam_search等功能,数据集是Cornell Movie Dialogs
Stars: ✭ 144 (-93.42%)
Mutual labels:  chatbot
Mojo Webqq
【重要通知:WebQQ将在2019年1月1日停止服务,此项目目前已停止维护,感谢大家四年来的一路陪伴】使用Perl语言(不会没关系)编写的smartqq/webqq客户端框架(非GUI),可通过插件提供基于HTTP协议的api接口供其他语言或系统调用
Stars: ✭ 1,755 (-19.79%)
Mutual labels:  chatbot
Peachpie
PeachPie - the PHP compiler and runtime for .NET and .NET Core
Stars: ✭ 1,945 (-11.11%)
Mutual labels:  dotnetcore
Rivescript Python
A RiveScript interpreter for Python. RiveScript is a scripting language for chatterbots.
Stars: ✭ 142 (-93.51%)
Mutual labels:  chatbot
Weihanli.common
common tools,methods,extension methods etc... .net 常用工具类,公共方法,常用扩展方法等,基础类库
Stars: ✭ 152 (-93.05%)
Mutual labels:  dotnetcore
Chatbot
🤖 Build your own chatbot base on IBM Watson
Stars: ✭ 142 (-93.51%)
Mutual labels:  chatbot
Dotnetcore
.NET 5 Nuget Packages.
Stars: ✭ 146 (-93.33%)
Mutual labels:  dotnetcore
Appmetrics
App Metrics is an open-source and cross-platform .NET library used to record and report metrics within an application.
Stars: ✭ 1,986 (-9.23%)
Mutual labels:  dotnetcore
Vue.netcore
.NetCore+Vue2/Vue3+Element plus,前后端分离,不一样的快速开发框架;提供Vue2、Vue3版本,。http://www.volcore.xyz/
Stars: ✭ 2,338 (+6.86%)
Mutual labels:  dotnetcore
Ptt Alertor
📢 Ptt 文章通知機器人!Notify Ptt Article in Realtime
Stars: ✭ 150 (-93.14%)
Mutual labels:  chatbot

logo

TensorFlow.NET (TF.NET) provides a .NET Standard binding for TensorFlow. It aims to implement the complete Tensorflow API in C# which allows .NET developers to develop, train and deploy Machine Learning models with the cross-platform .NET Standard framework. TensorFlow.NET has built-in Keras high-level interface and is released as an independent package TensorFlow.Keras.

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

master branch is based on tensorflow v2.x, v0.6x branch is based on tensorflow v2.6, v0.15-tensorflow1.15 is from tensorflow1.15.

tensors_flowing

Why TensorFlow in C# and F# ?

SciSharp STACK'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. Since the APIs are kept as similar as possible you can immediately adapt any existing TensorFlow code in C# or F# 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# or F#.

Go through the online docs TensorFlow for .NET before you get started with Machine Learning in .NET.

How to use

TensorFlow tf native1.14, cuda 10.0 tf native 1.15, cuda 10.0 tf native 2.3, cuda 10.1 tf native 2.4, cuda 11
tf.net 0.4x, tf.keras 0.5 x
tf.net 0.3x, tf.keras 0.4 x
tf.net 0.2x x x
tf.net 0.15 x x
tf.net 0.14 x

Troubleshooting of running example or installation, please refer here.

There are many examples reside at TensorFlow.NET Examples written in C# and F#.

C# Example

Install TF.NET and TensorFlow binary through NuGet.

### install tensorflow C#/F# binding
PM> Install-Package TensorFlow.NET
### install keras for tensorflow
PM> Install-Package TensorFlow.Keras

### Install tensorflow binary
### For CPU version
PM> Install-Package SciSharp.TensorFlow.Redist

### For GPU version (CUDA and cuDNN are required)
PM> Install-Package SciSharp.TensorFlow.Redist-Windows-GPU

Import TF.NET and Keras API in your project.

using static Tensorflow.Binding;
using static Tensorflow.KerasApi;
using Tensorflow;
using Tensorflow.NumPy;

Linear Regression in Eager mode:

// Parameters        
var training_steps = 1000;
var learning_rate = 0.01f;
var display_step = 100;

// Sample data
var X = np.array(3.3f, 4.4f, 5.5f, 6.71f, 6.93f, 4.168f, 9.779f, 6.182f, 7.59f, 2.167f,
             7.042f, 10.791f, 5.313f, 7.997f, 5.654f, 9.27f, 3.1f);
var Y = np.array(1.7f, 2.76f, 2.09f, 3.19f, 1.694f, 1.573f, 3.366f, 2.596f, 2.53f, 1.221f,
             2.827f, 3.465f, 1.65f, 2.904f, 2.42f, 2.94f, 1.3f);
var n_samples = X.shape[0];

// We can set a fixed init value in order to demo
var W = tf.Variable(-0.06f, name: "weight");
var b = tf.Variable(-0.73f, name: "bias");
var optimizer = keras.optimizers.SGD(learning_rate);

// Run training for the given number of steps.
foreach (var step in range(1, training_steps + 1))
{
    // Run the optimization to update W and b values.
    // Wrap computation inside a GradientTape for automatic differentiation.
    using var g = tf.GradientTape();
    // Linear regression (Wx + b).
    var pred = W * X + b;
    // Mean square error.
    var loss = tf.reduce_sum(tf.pow(pred - Y, 2)) / (2 * n_samples);
    // should stop recording
    // Compute gradients.
    var gradients = g.gradient(loss, (W, b));

    // Update W and b following gradients.
    optimizer.apply_gradients(zip(gradients, (W, b)));

    if (step % display_step == 0)
    {
        pred = W * X + b;
        loss = tf.reduce_sum(tf.pow(pred - Y, 2)) / (2 * n_samples);
        print($"step: {step}, loss: {loss.numpy()}, W: {W.numpy()}, b: {b.numpy()}");
    }
}

Run this example in Jupyter Notebook.

Toy version of ResNet in Keras functional API:

var layers = new LayersApi();
// input layer
var inputs = keras.Input(shape: (32, 32, 3), name: "img");
// convolutional layer
var x = layers.Conv2D(32, 3, activation: "relu").Apply(inputs);
x = layers.Conv2D(64, 3, activation: "relu").Apply(x);
var block_1_output = layers.MaxPooling2D(3).Apply(x);
x = layers.Conv2D(64, 3, activation: "relu", padding: "same").Apply(block_1_output);
x = layers.Conv2D(64, 3, activation: "relu", padding: "same").Apply(x);
var block_2_output = layers.Add().Apply(new Tensors(x, block_1_output));
x = layers.Conv2D(64, 3, activation: "relu", padding: "same").Apply(block_2_output);
x = layers.Conv2D(64, 3, activation: "relu", padding: "same").Apply(x);
var block_3_output = layers.Add().Apply(new Tensors(x, block_2_output));
x = layers.Conv2D(64, 3, activation: "relu").Apply(block_3_output);
x = layers.GlobalAveragePooling2D().Apply(x);
x = layers.Dense(256, activation: "relu").Apply(x);
x = layers.Dropout(0.5f).Apply(x);
// output layer
var outputs = layers.Dense(10).Apply(x);
// build keras model
var model = keras.Model(inputs, outputs, name: "toy_resnet");
model.summary();
// compile keras model in tensorflow static graph
model.compile(optimizer: keras.optimizers.RMSprop(1e-3f),
    loss: keras.losses.CategoricalCrossentropy(from_logits: true),
    metrics: new[] { "acc" });
// prepare dataset
var ((x_train, y_train), (x_test, y_test)) = keras.datasets.cifar10.load_data();
x_train = x_train / 255.0f;
y_train = np_utils.to_categorical(y_train, 10);
// training
model.fit(x_train[new Slice(0, 2000)], y_train[new Slice(0, 2000)],
          batch_size: 64,
          epochs: 10,
          validation_split: 0.2f);

F# Example

Linear Regression in Eager mode:

#r "nuget: TensorFlow.Net"
#r "nuget: TensorFlow.Keras"
#r "nuget: SciSharp.TensorFlow.Redist"

open Tensorflow
open Tensorflow.NumPy
open type Tensorflow.Binding
open type Tensorflow.KerasApi

let tf = New<tensorflow>()
tf.enable_eager_execution()

// Parameters
let training_steps = 1000
let learning_rate = 0.01f
let display_step = 100

// Sample data
let train_X = 
    np.array(3.3f, 4.4f, 5.5f, 6.71f, 6.93f, 4.168f, 9.779f, 6.182f, 7.59f, 2.167f,
             7.042f, 10.791f, 5.313f, 7.997f, 5.654f, 9.27f, 3.1f)
let train_Y = 
    np.array(1.7f, 2.76f, 2.09f, 3.19f, 1.694f, 1.573f, 3.366f, 2.596f, 2.53f, 1.221f,
             2.827f, 3.465f, 1.65f, 2.904f, 2.42f, 2.94f, 1.3f)
let n_samples = train_X.shape.[0]

// We can set a fixed init value in order to demo
let W = tf.Variable(-0.06f,name = "weight")
let b = tf.Variable(-0.73f, name = "bias")
let optimizer = keras.optimizers.SGD(learning_rate)

// Run training for the given number of steps.
for step = 1 to  (training_steps + 1) do 
    // Run the optimization to update W and b values.
    // Wrap computation inside a GradientTape for automatic differentiation.
    use g = tf.GradientTape()
    // Linear regression (Wx + b).
    let pred = W * train_X + b
    // Mean square error.
    let loss = tf.reduce_sum(tf.pow(pred - train_Y,2)) / (2 * n_samples)
    // should stop recording
    // compute gradients
    let gradients = g.gradient(loss,struct (W,b))

    // Update W and b following gradients.
    optimizer.apply_gradients(zip(gradients, struct (W,b)))

    if (step % display_step) = 0 then
        let pred = W * train_X + b
        let loss = tf.reduce_sum(tf.pow(pred-train_Y,2)) / (2 * n_samples)
        printfn $"step: {step}, loss: {loss.numpy()}, W: {W.numpy()}, b: {b.numpy()}"

Read the book The Definitive Guide to Tensorflow.NET if you want to know more about TensorFlow for .NET under the hood.

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
  • Port Tensorflow unit tests from Python to C# or F#
  • Port missing Tensorflow code from Python to C# or F#
  • Port Tensorflow examples to C# or F# and raise issues if you come accross missing parts of the API
  • Debug one of the unit tests that is marked as Ignored to get it to work
  • Debug one of the not yet working examples and get it to work

How to debug unit tests:

The best way to find out why a unit test is failing is to single step it in C# or F# and its corresponding 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.

Git Knowhow for Contributors

Add SciSharp/TensorFlow.NET as upstream to your local repo ...

git remote add upstream [email protected]:SciSharp/TensorFlow.NET.git

Please make sure you keep your fork up to date by regularly pulling from upstream.

git pull upstream master

Contact

Follow us on Twitter, Facebook, Medium, LinkedIn.

Join our chat on Gitter.

WeChat Sponsor 微信打赏:

SciSharp STACK

TensorFlow.NET is a part of SciSharp STACK

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].