Skip to content

Commit 69889a3

Browse files
SanftMonsterOceania2018
authored andcommitted
Refine the readme structure.
1 parent 89c68cd commit 69889a3

2 files changed

Lines changed: 122 additions & 94 deletions

File tree

README.md

Lines changed: 67 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111

1212
English | [中文](docs/Readme-CN.md)
1313

14-
*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.*
14+
*master branch is corresponding to tensorflow v2.10, v0.6x branch is from tensorflow v2.6, v0.15-tensorflow1.15 is from tensorflow1.15.*
1515

1616

1717
![tensors_flowing](docs/assets/tensors_flowing.gif)
1818

19-
### Why TensorFlow.NET ?
19+
## Why TensorFlow.NET ?
2020

2121
`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.
2222

@@ -28,58 +28,56 @@ In comparison to other projects, like for instance [TensorFlowSharp](https://www
2828

2929
[ML.NET](https://github.com/dotnet/machinelearning) also support using tensorflow as backend to train and infer your model, which provides better integration with .NET.
3030

31-
Go through the online docs [TensorFlow for .NET](https://scisharp.github.io/tensorflow-net-docs) before you get started with Machine Learning in .NET.
31+
## Documention
3232

33-
### How to use
33+
Introduction and simple examples:[Tensorflow.NET Documents](https://scisharp.github.io/tensorflow-net-docs)
3434

35-
| 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 |
36-
| -------------------------- | ------------- | -------------- | ------------- | ------------- |
37-
| tf.net 0.4x, tf.keras 0.5 | | | | x |
38-
| tf.net 0.3x, tf.keras 0.4 | | | x | |
39-
| tf.net 0.2x | | x | x | |
40-
| tf.net 0.15 | x | x | | |
41-
| tf.net 0.14 | x | | | |
35+
Detailed documention:[The Definitive Guide to Tensorflow.NET](https://tensorflownet.readthedocs.io/en/latest/FrontCover.html)
4236

43-
Troubleshooting of running example or installation, please refer [here](tensorflowlib/README.md).
37+
Examples:[TensorFlow.NET Examples](https://github.com/SciSharp/TensorFlow.NET-Examples)
4438

45-
There are many examples reside at [TensorFlow.NET Examples](https://github.com/SciSharp/TensorFlow.NET-Examples) written in C# and F#.
39+
Troubleshooting of running example or installation:[Tensorflow.NET FAQ](tensorflowlib/README.md)
4640

47-
#### TensorFlow.net Version
48-
` tf.net 0.4x -> tf native 2.4`
49-
`tf.net 0.6x -> tf native 2.6`
50-
`tf.net 0.7x -> tf native 2.7`
51-
`tf.net 0.10x -> tf native 2.10`
52-
`...`
41+
## Usage
5342

54-
#### C# Example
43+
### Installation
44+
45+
You can search the package name in NuGet Manager, or use the commands below in pckage manager console.
46+
47+
The installation contains two parts, the first is the main body:
5548

56-
Install TF.NET and TensorFlow binary through NuGet.
5749
```sh
58-
### install tensorflow C#/F# binding
50+
### Install Tensorflow.NET
5951
PM> Install-Package TensorFlow.NET
60-
### install keras for tensorflow
52+
53+
### Install Tensorflow.Keras
6154
PM> Install-Package TensorFlow.Keras
55+
```
56+
57+
The second part is the computing support part. Only one of the following packages is needed, depending on your device and system.
6258

63-
### Install tensorflow binary
64-
### For CPU version
59+
```
60+
### Cpu version for Windows, Linux and Mac
6561
PM> Install-Package SciSharp.TensorFlow.Redist
6662
67-
### For GPU version (CUDA and cuDNN are required)
63+
### Gpu version for Windows (CUDA and CUDNN are required)
6864
PM> Install-Package SciSharp.TensorFlow.Redist-Windows-GPU
65+
66+
### Gpu version for Linux (CUDA and CUDNN are required)
67+
PM> Install-Package SciSharp.TensorFlow.Redist-Linux-GPU
6968
```
7069

71-
Import TF.NET and Keras API in your project.
70+
71+
Two simple examples are given here to introduce the basic usage of Tensorflow.NET. As you can see, it's easy to write C# code just like that in Python.
72+
73+
### Example - Linear Regression in `Eager` mode
7274

7375
```csharp
7476
using static Tensorflow.Binding;
7577
using static Tensorflow.KerasApi;
7678
using Tensorflow;
7779
using Tensorflow.NumPy;
78-
```
79-
80-
Linear Regression in `Eager` mode:
8180

82-
```csharp
8381
// Parameters
8482
var training_steps = 1000;
8583
var learning_rate = 0.01f;
@@ -125,9 +123,14 @@ foreach (var step in range(1, training_steps + 1))
125123

126124
Run this example in [Jupyter Notebook](https://github.com/SciSharp/SciSharpCube).
127125

128-
Toy version of `ResNet` in `Keras` functional API:
126+
### Example - Toy version of `ResNet` in `Keras` functional API
129127

130128
```csharp
129+
using static Tensorflow.Binding;
130+
using static Tensorflow.KerasApi;
131+
using Tensorflow;
132+
using Tensorflow.NumPy;
133+
131134
var layers = new LayersApi();
132135
// input layer
133136
var inputs = keras.Input(shape: (32, 32, 3), name: "img");
@@ -165,83 +168,52 @@ model.fit(x_train[new Slice(0, 2000)], y_train[new Slice(0, 2000)],
165168
validation_split: 0.2f);
166169
```
167170

168-
#### F# Example
171+
The F# example for linear regression is available [here](docs/Example-fsharp.md).
169172

170-
Linear Regression in `Eager` mode:
173+
More adcanced examples could be found in [TensorFlow.NET Examples](https://github.com/SciSharp/TensorFlow.NET-Examples).
171174

172-
```fsharp
173-
#r "nuget: TensorFlow.Net"
174-
#r "nuget: TensorFlow.Keras"
175-
#r "nuget: SciSharp.TensorFlow.Redist"
175+
## Version Relationships
176176

177-
open Tensorflow
178-
open Tensorflow.NumPy
179-
open type Tensorflow.Binding
180-
open type Tensorflow.KerasApi
177+
| TensorFlow.NET Versions | tensorflow 1.14, cuda 10.0 | tensorflow 1.15, cuda 10.0 | tensorflow 2.3, cuda 10.1 | tensorflow 2.4, cuda 11 | tensorflow 2.7, cuda 11 |tensorflow 2.10, cuda 11 |
178+
| -------------------------- | ------------- | -------------- | ------------- | ------------- | ------------ | ------------ |
179+
| tf.net 0.10x, tf.keras 0.10 | | | | | | x |
180+
| tf.net 0.7x, tf.keras 0.7 | | | | | x | |
181+
| tf.net 0.4x, tf.keras 0.5 | | | | x | | |
182+
| tf.net 0.3x, tf.keras 0.4 | | | x | | | |
183+
| tf.net 0.2x | | x | x | | | |
184+
| tf.net 0.15 | x | x | | | | |
185+
| tf.net 0.14 | x | | | | | |
181186

182-
let tf = New<tensorflow>()
183-
tf.enable_eager_execution()
184187

185-
// Parameters
186-
let training_steps = 1000
187-
let learning_rate = 0.01f
188-
let display_step = 100
189-
190-
// Sample data
191-
let train_X =
192-
np.array(3.3f, 4.4f, 5.5f, 6.71f, 6.93f, 4.168f, 9.779f, 6.182f, 7.59f, 2.167f,
193-
7.042f, 10.791f, 5.313f, 7.997f, 5.654f, 9.27f, 3.1f)
194-
let train_Y =
195-
np.array(1.7f, 2.76f, 2.09f, 3.19f, 1.694f, 1.573f, 3.366f, 2.596f, 2.53f, 1.221f,
196-
2.827f, 3.465f, 1.65f, 2.904f, 2.42f, 2.94f, 1.3f)
197-
let n_samples = train_X.shape.[0]
198-
199-
// We can set a fixed init value in order to demo
200-
let W = tf.Variable(-0.06f,name = "weight")
201-
let b = tf.Variable(-0.73f, name = "bias")
202-
let optimizer = keras.optimizers.SGD(learning_rate)
203-
204-
// Run training for the given number of steps.
205-
for step = 1 to (training_steps + 1) do
206-
// Run the optimization to update W and b values.
207-
// Wrap computation inside a GradientTape for automatic differentiation.
208-
use g = tf.GradientTape()
209-
// Linear regression (Wx + b).
210-
let pred = W * train_X + b
211-
// Mean square error.
212-
let loss = tf.reduce_sum(tf.pow(pred - train_Y,2)) / (2 * n_samples)
213-
// should stop recording
214-
// compute gradients
215-
let gradients = g.gradient(loss,struct (W,b))
216-
217-
// Update W and b following gradients.
218-
optimizer.apply_gradients(zip(gradients, struct (W,b)))
219-
220-
if (step % display_step) = 0 then
221-
let pred = W * train_X + b
222-
let loss = tf.reduce_sum(tf.pow(pred-train_Y,2)) / (2 * n_samples)
223-
printfn $"step: {step}, loss: {loss.numpy()}, W: {W.numpy()}, b: {b.numpy()}"
188+
```
189+
tf.net 0.4x -> tf native 2.4
190+
tf.net 0.6x -> tf native 2.6
191+
tf.net 0.7x -> tf native 2.7
192+
tf.net 0.10x -> tf native 2.10
193+
...
224194
```
225195

226-
Read the book [The Definitive Guide to Tensorflow.NET](https://tensorflownet.readthedocs.io/en/latest/FrontCover.html) if you want to know more about TensorFlow for .NET under the hood.
196+
## Contribution:
227197

228-
### Contribute:
198+
Feel like contributing to one of the hottest projects in the Machine Learning field? Want to know how Tensorflow magically creates the computational graph?
229199

230-
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.
200+
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.
231201

232202
You can:
233-
* Let everyone know about this project
234-
* Port Tensorflow unit tests from Python to C# or F#
235-
* Port missing Tensorflow code from Python to C# or F#
236-
* Port Tensorflow examples to C# or F# and raise issues if you come accross missing parts of the API
237-
* Debug one of the unit tests that is marked as Ignored to get it to work
238-
* Debug one of the not yet working examples and get it to work
203+
- Star Tensorflow.NET or share it with others
204+
- Tell us about the missing APIs compared to Tensorflow
205+
- Port Tensorflow unit tests from Python to C# or F#
206+
- Port Tensorflow examples to C# or F# and raise issues if you come accross missing parts of the API or BUG
207+
- Debug one of the unit tests that is marked as Ignored to get it to work
208+
- Debug one of the not yet working examples and get it to work
209+
- Help us to complete the documentions.
239210

240-
### How to debug unit tests:
211+
212+
#### How to debug unit tests:
241213

242214
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.
243215

244-
### Git Knowhow for Contributors
216+
#### Git Knowhow for Contributors
245217

246218
Add SciSharp/TensorFlow.NET as upstream to your local repo ...
247219
```git
@@ -252,6 +224,7 @@ Please make sure you keep your fork up to date by regularly pulling from upstrea
252224
```git
253225
git pull upstream master
254226
```
227+
255228
### Support
256229
Buy our book to make open source project be sustainable [TensorFlow.NET实战](https://item.jd.com/13441549.html)
257230
<p float="left">

docs/Example-fsharp.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
Linear Regression in `Eager` mode:
2+
3+
```fsharp
4+
#r "nuget: TensorFlow.Net"
5+
#r "nuget: TensorFlow.Keras"
6+
#r "nuget: SciSharp.TensorFlow.Redist"
7+
8+
open Tensorflow
9+
open Tensorflow.NumPy
10+
open type Tensorflow.Binding
11+
open type Tensorflow.KerasApi
12+
13+
let tf = New<tensorflow>()
14+
tf.enable_eager_execution()
15+
16+
// Parameters
17+
let training_steps = 1000
18+
let learning_rate = 0.01f
19+
let display_step = 100
20+
21+
// Sample data
22+
let train_X =
23+
np.array(3.3f, 4.4f, 5.5f, 6.71f, 6.93f, 4.168f, 9.779f, 6.182f, 7.59f, 2.167f,
24+
7.042f, 10.791f, 5.313f, 7.997f, 5.654f, 9.27f, 3.1f)
25+
let train_Y =
26+
np.array(1.7f, 2.76f, 2.09f, 3.19f, 1.694f, 1.573f, 3.366f, 2.596f, 2.53f, 1.221f,
27+
2.827f, 3.465f, 1.65f, 2.904f, 2.42f, 2.94f, 1.3f)
28+
let n_samples = train_X.shape.[0]
29+
30+
// We can set a fixed init value in order to demo
31+
let W = tf.Variable(-0.06f,name = "weight")
32+
let b = tf.Variable(-0.73f, name = "bias")
33+
let optimizer = keras.optimizers.SGD(learning_rate)
34+
35+
// Run training for the given number of steps.
36+
for step = 1 to (training_steps + 1) do
37+
// Run the optimization to update W and b values.
38+
// Wrap computation inside a GradientTape for automatic differentiation.
39+
use g = tf.GradientTape()
40+
// Linear regression (Wx + b).
41+
let pred = W * train_X + b
42+
// Mean square error.
43+
let loss = tf.reduce_sum(tf.pow(pred - train_Y,2)) / (2 * n_samples)
44+
// should stop recording
45+
// compute gradients
46+
let gradients = g.gradient(loss,struct (W,b))
47+
48+
// Update W and b following gradients.
49+
optimizer.apply_gradients(zip(gradients, struct (W,b)))
50+
51+
if (step % display_step) = 0 then
52+
let pred = W * train_X + b
53+
let loss = tf.reduce_sum(tf.pow(pred-train_Y,2)) / (2 * n_samples)
54+
printfn $"step: {step}, loss: {loss.numpy()}, W: {W.numpy()}, b: {b.numpy()}"
55+
```

0 commit comments

Comments
 (0)