Browse Source

Graph

tags/v0.1.0-Tensor
Oceania2018 6 years ago
parent
commit
c102715be0
10 changed files with 154 additions and 2 deletions
  1. +17
    -1
      README.md
  2. BIN
      docs/assets/tensors_flowing.gif
  3. +24
    -0
      src/TensorFlowNET.Core/Graph.cs
  4. +16
    -0
      src/TensorFlowNET.Core/Operation.cs
  5. +22
    -0
      src/TensorFlowNET.Core/Tensorflow.cs
  6. +1
    -1
      tensorflowlib/README.md
  7. +27
    -0
      test/TensorFlowNET.Examples/HelloWorld.cs
  8. +11
    -0
      test/TensorFlowNET.Examples/IExample.cs
  9. +18
    -0
      test/TensorFlowNET.UnitTest/GraphTest.cs
  10. +18
    -0
      test/TensorFlowNET.UnitTest/OperationsTest.cs

+ 17
- 1
README.md View File

@@ -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.
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()
{

}
}
}
```

BIN
docs/assets/tensors_flowing.gif View File

Before After
Width: 252  |  Height: 448  |  Size: 383 kB

+ 24
- 0
src/TensorFlowNET.Core/Graph.cs View File

@@ -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;
}
}
}

+ 16
- 0
src/TensorFlowNET.Core/Operation.cs View File

@@ -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;
}
}
}

+ 22
- 0
src/TensorFlowNET.Core/Tensorflow.cs View File

@@ -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>(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;
}
}
}

+ 1
- 1
tensorflowlib/README.md View File

@@ -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
- Windows: https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-windows-x86_64-1.12.0.zip

+ 27
- 0
test/TensorFlowNET.Examples/HelloWorld.cs View File

@@ -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();
}
}
}

+ 11
- 0
test/TensorFlowNET.Examples/IExample.cs View File

@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace TensorFlowNET.Examples
{
public interface IExample
{
void Run();
}
}

+ 18
- 0
test/TensorFlowNET.UnitTest/GraphTest.cs View File

@@ -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();
}
}
}

+ 18
- 0
test/TensorFlowNET.UnitTest/OperationsTest.cs View File

@@ -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);
}
}
}

Loading…
Cancel
Save