diff --git a/README.md b/README.md index 46827774..f1aa73f7 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,20 @@ TensorFlow.NET provides .NET Standard binding for [TensorFlow](https://www.tensorflow.org/). -TensorFlow.NET is a member project of SciSharp stack. \ No newline at end of file +TensorFlow.NET is a member project of SciSharp stack. + +### How to use +```cs +using tf = TensorFlowNET.Core.Tensorflow; + +namespace TensorFlowNET.Examples +{ + public class HelloWorld : IExample + { + public void Run() + { + + } + } +} +``` \ No newline at end of file diff --git a/docs/assets/tensors_flowing.gif b/docs/assets/tensors_flowing.gif new file mode 100644 index 00000000..a12ac8da Binary files /dev/null and b/docs/assets/tensors_flowing.gif differ diff --git a/src/TensorFlowNET.Core/Graph.cs b/src/TensorFlowNET.Core/Graph.cs new file mode 100644 index 00000000..66b947ef --- /dev/null +++ b/src/TensorFlowNET.Core/Graph.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace TensorFlowNET.Core +{ + /// + /// TensorFlow uses a dataflow graph to represent your computation in terms of the dependencies between individual operations. + /// This leads to a low-level programming model in which you first define the dataflow graph, + /// then create a TensorFlow session to run parts of the graph across a set of local and remote devices. + /// https://www.tensorflow.org/guide/graphs + /// + public class Graph + { + public IntPtr TFGraph { get; set; } + + public Operation create_op() + { + var op = new Operation(this); + + return op; + } + } +} diff --git a/src/TensorFlowNET.Core/Operation.cs b/src/TensorFlowNET.Core/Operation.cs new file mode 100644 index 00000000..9128234a --- /dev/null +++ b/src/TensorFlowNET.Core/Operation.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace TensorFlowNET.Core +{ + public class Operation + { + private Graph _graph; + + public Operation(Graph g) + { + _graph = g; + } + } +} diff --git a/src/TensorFlowNET.Core/Tensorflow.cs b/src/TensorFlowNET.Core/Tensorflow.cs index 613fb177..471fafae 100644 --- a/src/TensorFlowNET.Core/Tensorflow.cs +++ b/src/TensorFlowNET.Core/Tensorflow.cs @@ -13,5 +13,27 @@ namespace TensorFlowNET.Core public static extern unsafe IntPtr TF_Version(); public static string VERSION => Marshal.PtrToStringAnsi(TF_Version()); + + [DllImport(TensorFlowLibName)] + static extern unsafe IntPtr TF_NewOperation(IntPtr graph, string opType, string oper_name); + + [DllImport(TensorFlowLibName)] + static extern unsafe IntPtr TF_FinishOperation(IntPtr desc, IntPtr status); + + public static IntPtr constant(T value) + { + var g = Graph(); + return TF_NewOperation(g.TFGraph, "Const", "Const"); + } + + [DllImport(TensorFlowLibName)] + static extern unsafe IntPtr TF_NewGraph(); + + public static Graph Graph() + { + Graph g = new Graph(); + g.TFGraph = TF_NewGraph(); + return g; + } } } diff --git a/tensorflowlib/README.md b/tensorflowlib/README.md index 4b1107cc..ea6f02d5 100644 --- a/tensorflowlib/README.md +++ b/tensorflowlib/README.md @@ -4,4 +4,4 @@ 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 - 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-rc0.zip \ No newline at end of file +- Windows: https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-windows-x86_64-1.12.0.zip \ No newline at end of file diff --git a/test/TensorFlowNET.Examples/HelloWorld.cs b/test/TensorFlowNET.Examples/HelloWorld.cs new file mode 100644 index 00000000..3a14e2da --- /dev/null +++ b/test/TensorFlowNET.Examples/HelloWorld.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Text; +using tf = TensorFlowNET.Core.Tensorflow; + +namespace TensorFlowNET.Examples +{ + /// + /// Simple hello world using TensorFlow + /// https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/1_Introduction/helloworld.py + /// + public class HelloWorld : IExample + { + public void Run() + { + /* # Create a Constant op + The op is added as a node to the default graph. + + The value returned by the constructor represents the output + of the Constant op.*/ + var hello = tf.constant("Hello, TensorFlow!"); + + // Start tf session + // var sess = tf.Session(); + } + } +} diff --git a/test/TensorFlowNET.Examples/IExample.cs b/test/TensorFlowNET.Examples/IExample.cs new file mode 100644 index 00000000..8908abe0 --- /dev/null +++ b/test/TensorFlowNET.Examples/IExample.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace TensorFlowNET.Examples +{ + public interface IExample + { + void Run(); + } +} diff --git a/test/TensorFlowNET.UnitTest/GraphTest.cs b/test/TensorFlowNET.UnitTest/GraphTest.cs new file mode 100644 index 00000000..d184c21e --- /dev/null +++ b/test/TensorFlowNET.UnitTest/GraphTest.cs @@ -0,0 +1,18 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using System.Collections.Generic; +using System.Text; +using tf = TensorFlowNET.Core.Tensorflow; + +namespace TensorFlowNET.UnitTest +{ + [TestClass] + public class GraphTest + { + [TestMethod] + public void ConstructGraph() + { + var g = tf.Graph(); + } + } +} diff --git a/test/TensorFlowNET.UnitTest/OperationsTest.cs b/test/TensorFlowNET.UnitTest/OperationsTest.cs new file mode 100644 index 00000000..352d282b --- /dev/null +++ b/test/TensorFlowNET.UnitTest/OperationsTest.cs @@ -0,0 +1,18 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using System.Collections.Generic; +using System.Text; +using tf = TensorFlowNET.Core.Tensorflow; + +namespace TensorFlowNET.UnitTest +{ + [TestClass] + public class OperationsTest + { + [TestMethod] + public void constant() + { + tf.constant(4.0); + } + } +}