diff --git a/README.md b/README.md index 6bce5b88..7021f15a 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # TensorFlow.NET -TensorFlow.NET provides .NET Standard binding for [TensorFlow](https://www.tensorflow.org/). +TensorFlow.NET provides .NET Standard binding for [TensorFlow](https://www.tensorflow.org/). It's the full complete binding in CSharp language for TensorFlow API. It allows .NET developers to develop, train and deploy Machine Learning models in .NET standard which is running on cross-platform. [![Join the chat at https://gitter.im/publiclab/publiclab](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/sci-sharp/community) [![Tensorflow.NET](https://ci.appveyor.com/api/projects/status/wx4td43v2d3f2xj6?svg=true)](https://ci.appveyor.com/project/Haiping-Chen/tensorflow-net) diff --git a/docs/assets/graph_vis_animation.gif b/docs/assets/graph_vis_animation.gif new file mode 100644 index 00000000..55638327 Binary files /dev/null and b/docs/assets/graph_vis_animation.gif differ diff --git a/docs/source/Graph.md b/docs/source/Graph.md index 10c54857..f6edbfc6 100644 --- a/docs/source/Graph.md +++ b/docs/source/Graph.md @@ -1,2 +1,23 @@ # Chapter. Graph +TensorFlow uses a **dataflow graph** to represent your computation in terms of the dependencies between individual operations. A graph defines the computation. It doesn't compute anything, it doesn't hold any values, it just defines the operations that you specified in your code. + +### Defining the Graph + +We define a graph with a variable and three operations: `variable` returns the current value of our variable. `initialize` assigns the initial value of 31 to that variable. `assign` assigns the new value of 12 to that variable. + +```csharp +with(tf.Graph().as_default(), graph => +{ + var variable = tf.Variable(31, name: "tree"); + tf.global_variables_initializer(); + variable.assign(12); +}); +``` + +TF.NET simulate a `with` syntax to manage the Graph lifecycle which will be disposed when the graph instance is no long need. The graph is also what the sessions in the next chapter use when not manually specifying a graph because use invoked the `as_default()`. + +A typical graph is looks like below: + +![image](../assets/graph_vis_animation.gif) + diff --git a/docs/source/Session.md b/docs/source/Session.md index a14816f4..d79d72ee 100644 --- a/docs/source/Session.md +++ b/docs/source/Session.md @@ -1,2 +1,24 @@ # Chapter. Session +TensorFlow **session** runs parts of the graph across a set of local and remote devices. A session allows to execute graphs or part of graphs. It allocates resources (on one or more machines) for that and holds the actual values of intermediate results and variables. + +### Running Computations in a Session + +Let's complete the example in last chapter. + +```csharp +with(tf.Graph(), graph => +{ + var variable = tf.Variable(31, name: "tree"); + var init = tf.global_variables_initializer(); + + var sess = tf.Session(graph); + sess.run(init); + + var result = sess.run(variable); // 31 + + var assign = variable.assign(12); + result = sess.run(assign); // 12 +}); +``` + diff --git a/docs/source/index.rst b/docs/source/index.rst index 298d2f92..2d84abdb 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -19,8 +19,8 @@ Welcome to TensorFlow.NET's documentation! Constant Variable Placeholder - Session Graph + Session Operation Attribute NameScope diff --git a/tensorflowlib/README.md b/tensorflowlib/README.md index f00cb66b..5dea59ee 100644 --- a/tensorflowlib/README.md +++ b/tensorflowlib/README.md @@ -1,10 +1,10 @@ Here are some pre-built TensorFlow binaries you can use for each platform: - Linux - - CPU-only: https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-linux-x86_64-1.12.0.tar.gz - - GPU-enabled: https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-gpu-linux-x86_64-1.12.0.tar.gz -- Mac: https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-darwin-x86_64-1.12.0.tar.gz -- Windows: https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-windows-x86_64-1.12.0.zip + - CPU-only: https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-linux-x86_64-1.13.1.tar.gz + - GPU-enabled: https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-gpu-linux-x86_64-1.13.1.tar.gz +- Mac: https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-darwin-x86_64-1.13.1.tar.gz +- Windows: https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-windows-x86_64-1.13.1.zip https://www.tensorflow.org/install/source_windows pacman -S git patch unzip diff --git a/test/TensorFlowNET.UnitTest/VariableTest.cs b/test/TensorFlowNET.UnitTest/VariableTest.cs index 19a5eb3f..88c65bd3 100644 --- a/test/TensorFlowNET.UnitTest/VariableTest.cs +++ b/test/TensorFlowNET.UnitTest/VariableTest.cs @@ -47,7 +47,27 @@ namespace TensorFlowNET.UnitTest } [TestMethod] - public void Assign() + public void Assign1() + { + with(tf.Graph().as_default(), graph => + { + var variable = tf.Variable(31, name: "tree"); + var init = tf.global_variables_initializer(); + + var sess = tf.Session(graph); + sess.run(init); + + var result = sess.run(variable); + Assert.IsTrue((int)result == 31); + + var assign = variable.assign(12); + result = sess.run(assign); + Assert.IsTrue((int)result == 12); + }); + } + + [TestMethod] + public void Assign2() { var v1 = tf.Variable(10.0f, name: "v1"); //tf.get_variable("v1", shape: new TensorShape(3), initializer: tf.zeros_initializer); var inc_v1 = v1.assign(v1 + 1.0f);