| @@ -2,7 +2,7 @@ | |||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||
| using System.Text; | using System.Text; | ||||
| namespace Tensorflow | |||||
| namespace Tensorflow.Eager | |||||
| { | { | ||||
| public class Context | public class Context | ||||
| { | { | ||||
| @@ -0,0 +1,26 @@ | |||||
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Text; | |||||
| namespace Tensorflow.Eager | |||||
| { | |||||
| public class ContextOptions : IDisposable | |||||
| { | |||||
| private IntPtr _handle; | |||||
| public ContextOptions() | |||||
| { | |||||
| _handle = c_api.TFE_NewContextOptions(); | |||||
| } | |||||
| public void Dispose() | |||||
| { | |||||
| c_api.TFE_DeleteContextOptions(_handle); | |||||
| } | |||||
| public static implicit operator IntPtr(ContextOptions ctx) | |||||
| { | |||||
| return ctx._handle; | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -102,16 +102,21 @@ namespace Tensorflow | |||||
| /// <param name="func_graphs"></param> | /// <param name="func_graphs"></param> | ||||
| private static void _MarkReachedOps(List<Operation> from_ops, List<Operation> reached_ops, List<object> func_graphs) | private static void _MarkReachedOps(List<Operation> from_ops, List<Operation> reached_ops, List<object> func_graphs) | ||||
| { | { | ||||
| foreach(var op in from_ops) | |||||
| Queue<Operation> queue = new Queue<Operation>(from_ops); | |||||
| while (queue.Count > 0) | |||||
| { | { | ||||
| reached_ops.Add(op); | |||||
| foreach(var output in op.outputs) | |||||
| var op = queue.Dequeue(); | |||||
| if (!reached_ops.Contains(op)) | |||||
| { | { | ||||
| reached_ops.AddRange(_Consumers(output, func_graphs)); | |||||
| reached_ops.Add(op); | |||||
| foreach (var output in op.outputs) | |||||
| { | |||||
| var c = _Consumers(output, func_graphs).ToList(); | |||||
| c.ForEach(x => queue.Enqueue(x)); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| reached_ops.Reverse(); | |||||
| } | } | ||||
| /// <summary> | /// <summary> | ||||
| @@ -12,6 +12,7 @@ namespace Tensorflow | |||||
| public bool _trainable; | public bool _trainable; | ||||
| public Tensor _variable; | public Tensor _variable; | ||||
| public Tensor _snapshot; | public Tensor _snapshot; | ||||
| public Operation op; | |||||
| public RefVariable(object initial_value, | public RefVariable(object initial_value, | ||||
| bool trainable = true, | bool trainable = true, | ||||
| @@ -91,6 +92,7 @@ namespace Tensorflow | |||||
| _snapshot = gen_array_ops.identity(_variable, name = "read"); | _snapshot = gen_array_ops.identity(_variable, name = "read"); | ||||
| } | } | ||||
| op = _initializer_op; | |||||
| ops.add_to_collections(collections, this); | ops.add_to_collections(collections, this); | ||||
| } | } | ||||
| } | } | ||||
| @@ -4,4 +4,8 @@ Here are some pre-built TensorFlow binaries you can use for each platform: | |||||
| - CPU-only: https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-linux-x86_64-1.12.0.tar.gz | - 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 | - 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 | - 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 | |||||
| - Windows: https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-windows-x86_64-1.12.0.zip | |||||
| https://www.tensorflow.org/install/source_windows | |||||
| pacman -S git patch unzip | |||||
| bazel build --config=opt //tensorflow:libtensorflow.so | |||||
| @@ -50,6 +50,8 @@ namespace TensorFlowNET.Examples | |||||
| // Note, minimize() knows to modify W and b because Variable objects are trainable=True by default | // Note, minimize() knows to modify W and b because Variable objects are trainable=True by default | ||||
| var optimizer = tf.train.GradientDescentOptimizer(learning_rate); | var optimizer = tf.train.GradientDescentOptimizer(learning_rate); | ||||
| optimizer.minimize(cost); | optimizer.minimize(cost); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -0,0 +1,34 @@ | |||||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | |||||
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Text; | |||||
| using Tensorflow; | |||||
| namespace TensorFlowNET.UnitTest | |||||
| { | |||||
| [TestClass] | |||||
| public class ConsumersTest : CApiTest | |||||
| { | |||||
| [TestMethod] | |||||
| public void Constant() | |||||
| { | |||||
| var X = tf.placeholder(tf.float64); | |||||
| var W = tf.constant(1.0D); | |||||
| var mul = tf.multiply(X, W); | |||||
| EXPECT_EQ(1, X.op.OutputNumConsumers(0)); | |||||
| EXPECT_EQ(1, W.op.OutputNumConsumers(0)); | |||||
| } | |||||
| [TestMethod] | |||||
| public void Variable() | |||||
| { | |||||
| var X = tf.placeholder(tf.float64); | |||||
| var W = tf.Variable(1.0D, name: "var"); | |||||
| var mul = tf.multiply(X, W); | |||||
| EXPECT_EQ(1, X.op.OutputNumConsumers(0)); | |||||
| EXPECT_EQ(1, W.op.OutputNumConsumers(0)); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,28 @@ | |||||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | |||||
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Text; | |||||
| using Tensorflow; | |||||
| namespace TensorFlowNET.UnitTest.Eager | |||||
| { | |||||
| /// <summary> | |||||
| /// tensorflow\c\eager\c_api_test.cc | |||||
| /// </summary> | |||||
| [TestClass] | |||||
| public class CApiVariableTest : CApiTest, IDisposable | |||||
| { | |||||
| Status status = new Status(); | |||||
| [TestMethod] | |||||
| public void Variables() | |||||
| { | |||||
| } | |||||
| public void Dispose() | |||||
| { | |||||
| } | |||||
| } | |||||
| } | |||||