@@ -37,15 +37,10 @@ namespace Tensorflow | |||||
{ | { | ||||
_handle = c_api.TF_NewGraph(); | _handle = c_api.TF_NewGraph(); | ||||
Status = new Status(); | Status = new Status(); | ||||
} | |||||
public Graph(IntPtr graph) | |||||
{ | |||||
_handle = graph; | |||||
Status = new Status(); | |||||
_nodes_by_id = new Dictionary<int, Operation>(); | _nodes_by_id = new Dictionary<int, Operation>(); | ||||
_nodes_by_name = new Dictionary<string, Operation>(); | _nodes_by_name = new Dictionary<string, Operation>(); | ||||
_names_in_use = new Dictionary<string, int>(); | _names_in_use = new Dictionary<string, int>(); | ||||
_graph_key = $"grap-key-{ops.uid()}/"; | |||||
} | } | ||||
public T as_graph_element<T>(T obj, bool allow_tensor = true, bool allow_operation = true) | public T as_graph_element<T>(T obj, bool allow_tensor = true, bool allow_operation = true) | ||||
@@ -28,6 +28,8 @@ namespace Tensorflow | |||||
TF_DataType dtype = TF_DataType.DtInvalid) : | TF_DataType dtype = TF_DataType.DtInvalid) : | ||||
base(initial_value, trainable, collections, validate_shape, caching_device, name, dtype) | base(initial_value, trainable, collections, validate_shape, caching_device, name, dtype) | ||||
{ | { | ||||
_in_graph_mode = true; | |||||
_init_from_args(initial_value, trainable, collections, validate_shape, caching_device, name, dtype); | _init_from_args(initial_value, trainable, collections, validate_shape, caching_device, name, dtype); | ||||
} | } | ||||
@@ -174,9 +174,16 @@ namespace Tensorflow | |||||
// outer_device_stack = None | // outer_device_stack = None | ||||
} | } | ||||
private static int uid_number = 0; | |||||
/// <summary> | |||||
/// A unique (within this program execution) integer. | |||||
/// Not thread safe | |||||
/// </summary> | |||||
/// <returns></returns> | |||||
public static int uid() | public static int uid() | ||||
{ | { | ||||
return 1; | |||||
return uid_number++; | |||||
} | } | ||||
} | } | ||||
} | } |
@@ -15,7 +15,7 @@ namespace Tensorflow | |||||
public static Context context; | public static Context context; | ||||
public static Graph g = new Graph(c_api.TF_NewGraph()); | |||||
public static Graph g = new Graph(); | |||||
public static RefVariable Variable<T>(T data, string name = "", TF_DataType dtype = TF_DataType.DtInvalid) | public static RefVariable Variable<T>(T data, string name = "", TF_DataType dtype = TF_DataType.DtInvalid) | ||||
{ | { | ||||
@@ -35,7 +35,7 @@ namespace TensorFlowNET.UnitTest | |||||
using (var session = tf.Session()) | using (var session = tf.Session()) | ||||
{ | { | ||||
session.run(model); | |||||
var sm = session.run(model); | |||||
for(int i = 0; i < 5; i++) | for(int i = 0; i < 5; i++) | ||||
{ | { | ||||
var x1 = x + 1; | var x1 = x + 1; | ||||