| @@ -1,5 +1,5 @@ | |||||
| # TensorFlow.NET | # 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. | |||||
| [](https://gitter.im/sci-sharp/community) | [](https://gitter.im/sci-sharp/community) | ||||
| [](https://ci.appveyor.com/project/Haiping-Chen/tensorflow-net) | [](https://ci.appveyor.com/project/Haiping-Chen/tensorflow-net) | ||||
| @@ -1,2 +1,23 @@ | |||||
| # Chapter. Graph | # 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<Graph>(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: | |||||
|  | |||||
| @@ -1,2 +1,24 @@ | |||||
| # Chapter. Session | # 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<Graph>(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 | |||||
| }); | |||||
| ``` | |||||
| @@ -19,8 +19,8 @@ Welcome to TensorFlow.NET's documentation! | |||||
| Constant | Constant | ||||
| Variable | Variable | ||||
| Placeholder | Placeholder | ||||
| Session | |||||
| Graph | Graph | ||||
| Session | |||||
| Operation | Operation | ||||
| Attribute | Attribute | ||||
| NameScope | NameScope | ||||
| @@ -1,10 +1,10 @@ | |||||
| Here are some pre-built TensorFlow binaries you can use for each platform: | Here are some pre-built TensorFlow binaries you can use for each platform: | ||||
| - Linux | - 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 | https://www.tensorflow.org/install/source_windows | ||||
| pacman -S git patch unzip | pacman -S git patch unzip | ||||
| @@ -47,7 +47,27 @@ namespace TensorFlowNET.UnitTest | |||||
| } | } | ||||
| [TestMethod] | [TestMethod] | ||||
| public void Assign() | |||||
| public void Assign1() | |||||
| { | |||||
| with<Graph>(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 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); | var inc_v1 = v1.assign(v1 + 1.0f); | ||||