You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 6.8 kB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. ![logo](docs/assets/tf.net.logo.png)
  2. **TensorFlow.NET** (TF.NET) provides a .NET Standard binding for [TensorFlow](https://www.tensorflow.org/). 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.
  3. [![Join the chat at https://gitter.im/publiclab/publiclab](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/sci-sharp/community)
  4. [![Tensorflow.NET](https://ci.appveyor.com/api/projects/status/wx4td43v2d3f2xj6?svg=true)](https://ci.appveyor.com/project/Haiping-Chen/tensorflow-net)
  5. [![NuGet](https://img.shields.io/nuget/dt/TensorFlow.NET.svg)](https://www.nuget.org/packages/TensorFlow.NET)
  6. [![Documentation Status](https://readthedocs.org/projects/tensorflownet/badge/?version=latest)](https://tensorflownet.readthedocs.io/en/latest/?badge=latest)
  7. [![Badge](https://img.shields.io/badge/link-996.icu-red.svg)](https://996.icu/#/en_US)
  8. [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/javiercp/BinderTF.NET/master?urlpath=lab)
  9. *master branch is based on tensorflow 2.3 now, v0.15-tensorflow1.15 is from tensorflow1.15.*
  10. ![tensors_flowing](docs/assets/tensors_flowing.gif)
  11. ### Why TensorFlow.NET ?
  12. `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# 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.
  13. ![pythn vs csharp](docs/assets/syntax-comparision.png)
  14. 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.
  15. 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#.
  16. ### How to use
  17. | TensorFlow | tf native1.14 | tf native 1.15 | tf native 2.3 |
  18. | ----------- | ------------- | -------------- | ------------- |
  19. | tf.net 0.20 | | x | x |
  20. | tf.net 0.15 | x | x | |
  21. | tf.net 0.14 | x | | |
  22. Install TF.NET and TensorFlow binary through NuGet.
  23. ```sh
  24. ### install tensorflow C# binding
  25. PM> Install-Package TensorFlow.NET
  26. ### Install tensorflow binary
  27. ### For CPU version
  28. PM> Install-Package SciSharp.TensorFlow.Redist
  29. ### For GPU version (CUDA and cuDNN are required)
  30. PM> Install-Package SciSharp.TensorFlow.Redist-Windows-GPU
  31. ```
  32. Import TF.NET in your project.
  33. ```cs
  34. using static Tensorflow.Binding;
  35. ```
  36. Linear Regression:
  37. ```c#
  38. // Parameters
  39. int training_steps = 1000;
  40. float learning_rate = 0.01f;
  41. int display_step = 100;
  42. // We can set a fixed init value in order to demo
  43. var W = tf.Variable(-0.06f, name: "weight");
  44. var b = tf.Variable(-0.73f, name: "bias");
  45. var optimizer = tf.optimizers.SGD(learning_rate);
  46. // Run training for the given number of steps.
  47. foreach (var step in range(1, training_steps + 1))
  48. {
  49. // Run the optimization to update W and b values.
  50. // Wrap computation inside a GradientTape for automatic differentiation.
  51. using var g = tf.GradientTape();
  52. // Linear regression (Wx + b).
  53. var pred = W * X + b;
  54. // Mean square error.
  55. var loss = tf.reduce_sum(tf.pow(pred - Y, 2)) / (2 * n_samples);
  56. // should stop recording
  57. // Compute gradients.
  58. var gradients = g.gradient(loss, (W, b));
  59. // Update W and b following gradients.
  60. optimizer.apply_gradients(zip(gradients, (W, b)));
  61. if (step % display_step == 0)
  62. {
  63. pred = W * X + b;
  64. loss = tf.reduce_sum(tf.pow(pred - Y, 2)) / (2 * n_samples);
  65. print($"step: {step}, loss: {loss.numpy()}, W: {W.numpy()}, b: {b.numpy()}");
  66. }
  67. }
  68. ```
  69. Run this example in [Jupyter Notebook](https://github.com/SciSharp/SciSharpCube).
  70. Read the docs & book [The Definitive Guide to Tensorflow.NET](https://tensorflownet.readthedocs.io/en/latest/FrontCover.html).
  71. There are many examples reside at [TensorFlow.NET Examples](https://github.com/SciSharp/TensorFlow.NET-Examples).
  72. Troubleshooting of running example or installation, please refer [here](tensorflowlib/README.md).
  73. ### Contribute:
  74. 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.
  75. You can:
  76. * Let everyone know about this project
  77. * Port Tensorflow unit tests from Python to C#
  78. * Port missing Tensorflow code from Python to C#
  79. * Port Tensorflow examples to C# and raise issues if you come accross missing parts of the API
  80. * Debug one of the unit tests that is marked as Ignored to get it to work
  81. * Debug one of the not yet working examples and get it to work
  82. ### How to debug unit tests:
  83. 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.
  84. ### Git Knowhow for Contributors
  85. Add SciSharp/TensorFlow.NET as upstream to your local repo ...
  86. ```git
  87. git remote add upstream git@github.com:SciSharp/TensorFlow.NET.git
  88. ```
  89. Please make sure you keep your fork up to date by regularly pulling from upstream.
  90. ```git
  91. git pull upstream master
  92. ```
  93. ### Contact
  94. Feel free to star or raise issue on [Github](https://github.com/SciSharp/TensorFlow.NET).
  95. Follow us on [Medium](https://medium.com/scisharp).
  96. Join our chat on [Gitter](https://gitter.im/sci-sharp/community).
  97. Scan QR code to join Tencent TIM group:
  98. ![SciSharp STACK](docs/TIM.jpg)
  99. WeChat Sponsor 微信打赏:
  100. ![SciSharp STACK](docs/assets/WeChatCollection.jpg)
  101. TensorFlow.NET is a part of [SciSharp STACK](https://scisharp.github.io/SciSharp/)
  102. <br>
  103. <a href="http://scisharpstack.org"><img src="https://github.com/SciSharp/SciSharp/blob/master/art/scisharp-stack.png" width="391" height="100" /></a>