| @@ -2,4 +2,20 @@ | |||||
| TensorFlow.NET provides .NET Standard binding for [TensorFlow](https://www.tensorflow.org/). | TensorFlow.NET provides .NET Standard binding for [TensorFlow](https://www.tensorflow.org/). | ||||
| TensorFlow.NET is a member project of SciSharp stack. | |||||
| 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() | |||||
| { | |||||
| } | |||||
| } | |||||
| } | |||||
| ``` | |||||
| @@ -0,0 +1,24 @@ | |||||
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Text; | |||||
| namespace TensorFlowNET.Core | |||||
| { | |||||
| /// <summary> | |||||
| /// 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 | |||||
| /// </summary> | |||||
| public class Graph | |||||
| { | |||||
| public IntPtr TFGraph { get; set; } | |||||
| public Operation create_op() | |||||
| { | |||||
| var op = new Operation(this); | |||||
| return op; | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -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; | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -13,5 +13,27 @@ namespace TensorFlowNET.Core | |||||
| public static extern unsafe IntPtr TF_Version(); | public static extern unsafe IntPtr TF_Version(); | ||||
| public static string VERSION => Marshal.PtrToStringAnsi(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>(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; | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| @@ -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 | - 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-rc0.zip | |||||
| - Windows: https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-windows-x86_64-1.12.0.zip | |||||
| @@ -0,0 +1,27 @@ | |||||
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Text; | |||||
| using tf = TensorFlowNET.Core.Tensorflow; | |||||
| namespace TensorFlowNET.Examples | |||||
| { | |||||
| /// <summary> | |||||
| /// Simple hello world using TensorFlow | |||||
| /// https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/1_Introduction/helloworld.py | |||||
| /// </summary> | |||||
| 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(); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,11 @@ | |||||
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Text; | |||||
| namespace TensorFlowNET.Examples | |||||
| { | |||||
| public interface IExample | |||||
| { | |||||
| void Run(); | |||||
| } | |||||
| } | |||||
| @@ -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(); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -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); | |||||
| } | |||||
| } | |||||
| } | |||||