Skip to content

Commit c102715

Browse files
committed
Graph
1 parent dc2db55 commit c102715

10 files changed

Lines changed: 154 additions & 2 deletions

File tree

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,20 @@
22
TensorFlow.NET provides .NET Standard binding for [TensorFlow](https://www.tensorflow.org/).
33

44

5-
TensorFlow.NET is a member project of SciSharp stack.
5+
TensorFlow.NET is a member project of SciSharp stack.
6+
7+
### How to use
8+
```cs
9+
using tf = TensorFlowNET.Core.Tensorflow;
10+
11+
namespace TensorFlowNET.Examples
12+
{
13+
public class HelloWorld : IExample
14+
{
15+
public void Run()
16+
{
17+
18+
}
19+
}
20+
}
21+
```

docs/assets/tensors_flowing.gif

374 KB
Loading

src/TensorFlowNET.Core/Graph.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace TensorFlowNET.Core
6+
{
7+
/// <summary>
8+
/// TensorFlow uses a dataflow graph to represent your computation in terms of the dependencies between individual operations.
9+
/// This leads to a low-level programming model in which you first define the dataflow graph,
10+
/// then create a TensorFlow session to run parts of the graph across a set of local and remote devices.
11+
/// https://www.tensorflow.org/guide/graphs
12+
/// </summary>
13+
public class Graph
14+
{
15+
public IntPtr TFGraph { get; set; }
16+
17+
public Operation create_op()
18+
{
19+
var op = new Operation(this);
20+
21+
return op;
22+
}
23+
}
24+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace TensorFlowNET.Core
6+
{
7+
public class Operation
8+
{
9+
private Graph _graph;
10+
11+
public Operation(Graph g)
12+
{
13+
_graph = g;
14+
}
15+
}
16+
}

src/TensorFlowNET.Core/Tensorflow.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,27 @@ public static class Tensorflow
1313
public static extern unsafe IntPtr TF_Version();
1414

1515
public static string VERSION => Marshal.PtrToStringAnsi(TF_Version());
16+
17+
[DllImport(TensorFlowLibName)]
18+
static extern unsafe IntPtr TF_NewOperation(IntPtr graph, string opType, string oper_name);
19+
20+
[DllImport(TensorFlowLibName)]
21+
static extern unsafe IntPtr TF_FinishOperation(IntPtr desc, IntPtr status);
22+
23+
public static IntPtr constant<T>(T value)
24+
{
25+
var g = Graph();
26+
return TF_NewOperation(g.TFGraph, "Const", "Const");
27+
}
28+
29+
[DllImport(TensorFlowLibName)]
30+
static extern unsafe IntPtr TF_NewGraph();
31+
32+
public static Graph Graph()
33+
{
34+
Graph g = new Graph();
35+
g.TFGraph = TF_NewGraph();
36+
return g;
37+
}
1638
}
1739
}

tensorflowlib/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ Here are some pre-built TensorFlow binaries you can use for each platform:
44
- CPU-only: https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-linux-x86_64-1.12.0.tar.gz
55
- GPU-enabled: https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-gpu-linux-x86_64-1.12.0.tar.gz
66
- Mac: https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-darwin-x86_64-1.12.0.tar.gz
7-
- Windows: https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-windows-x86_64-1.12.0-rc0.zip
7+
- Windows: https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-windows-x86_64-1.12.0.zip
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using tf = TensorFlowNET.Core.Tensorflow;
5+
6+
namespace TensorFlowNET.Examples
7+
{
8+
/// <summary>
9+
/// Simple hello world using TensorFlow
10+
/// https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/1_Introduction/helloworld.py
11+
/// </summary>
12+
public class HelloWorld : IExample
13+
{
14+
public void Run()
15+
{
16+
/* # Create a Constant op
17+
The op is added as a node to the default graph.
18+
19+
The value returned by the constructor represents the output
20+
of the Constant op.*/
21+
var hello = tf.constant("Hello, TensorFlow!");
22+
23+
// Start tf session
24+
// var sess = tf.Session();
25+
}
26+
}
27+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace TensorFlowNET.Examples
6+
{
7+
public interface IExample
8+
{
9+
void Run();
10+
}
11+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Text;
5+
using tf = TensorFlowNET.Core.Tensorflow;
6+
7+
namespace TensorFlowNET.UnitTest
8+
{
9+
[TestClass]
10+
public class GraphTest
11+
{
12+
[TestMethod]
13+
public void ConstructGraph()
14+
{
15+
var g = tf.Graph();
16+
}
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Text;
5+
using tf = TensorFlowNET.Core.Tensorflow;
6+
7+
namespace TensorFlowNET.UnitTest
8+
{
9+
[TestClass]
10+
public class OperationsTest
11+
{
12+
[TestMethod]
13+
public void constant()
14+
{
15+
tf.constant(4.0);
16+
}
17+
}
18+
}

0 commit comments

Comments
 (0)