Skip to content

Commit 43273b3

Browse files
committed
fixed #108
1 parent aecaa78 commit 43273b3

File tree

5 files changed

+13
-9
lines changed

5 files changed

+13
-9
lines changed

src/TensorFlowNET.Core/Graphs/Graph.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,10 @@ public Graph()
3737
{
3838
_handle = c_api.TF_NewGraph();
3939
Status = new Status();
40-
}
41-
42-
public Graph(IntPtr graph)
43-
{
44-
_handle = graph;
45-
Status = new Status();
4640
_nodes_by_id = new Dictionary<int, Operation>();
4741
_nodes_by_name = new Dictionary<string, Operation>();
4842
_names_in_use = new Dictionary<string, int>();
43+
_graph_key = $"grap-key-{ops.uid()}/";
4944
}
5045

5146
public T as_graph_element<T>(T obj, bool allow_tensor = true, bool allow_operation = true)

src/TensorFlowNET.Core/Variables/RefVariable.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public RefVariable(object initial_value,
2828
TF_DataType dtype = TF_DataType.DtInvalid) :
2929
base(initial_value, trainable, collections, validate_shape, caching_device, name, dtype)
3030
{
31+
_in_graph_mode = true;
32+
3133
_init_from_args(initial_value, trainable, collections, validate_shape, caching_device, name, dtype);
3234
}
3335

src/TensorFlowNET.Core/ops.py.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,16 @@ public static void init_scope()
174174
// outer_device_stack = None
175175
}
176176

177+
private static int uid_number = 0;
178+
179+
/// <summary>
180+
/// A unique (within this program execution) integer.
181+
/// Not thread safe
182+
/// </summary>
183+
/// <returns></returns>
177184
public static int uid()
178185
{
179-
return 1;
186+
return uid_number++;
180187
}
181188
}
182189
}

src/TensorFlowNET.Core/tf.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public static partial class tf
1515

1616
public static Context context;
1717

18-
public static Graph g = new Graph(c_api.TF_NewGraph());
18+
public static Graph g = new Graph();
1919

2020
public static RefVariable Variable<T>(T data, string name = "", TF_DataType dtype = TF_DataType.DtInvalid)
2121
{

test/TensorFlowNET.UnitTest/VariableTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void Add()
3535

3636
using (var session = tf.Session())
3737
{
38-
session.run(model);
38+
var sm = session.run(model);
3939
for(int i = 0; i < 5; i++)
4040
{
4141
var x1 = x + 1;

0 commit comments

Comments
 (0)