diff --git a/src/TensorFlowNET.Core/Data/MapDataset.cs b/src/TensorFlowNET.Core/Data/MapDataset.cs index 1f843e4a..df7becc4 100644 --- a/src/TensorFlowNET.Core/Data/MapDataset.cs +++ b/src/TensorFlowNET.Core/Data/MapDataset.cs @@ -15,11 +15,11 @@ namespace Tensorflow bool preserve_cardinality = false, bool use_legacy_function = false) : base(input_dataset) { - var func = new ConcreteFunction($"{map_func.Method.Name}_{Guid.NewGuid()}"); + var func = new ConcreteFunction($"{map_func.Method.Name}_{Tensorflow.ops.uid_function()}"); func.Enter(); var inputs = new Tensors(); foreach (var input in input_dataset.element_spec) - inputs.Add(tf.placeholder(input.dtype, shape: input.shape)); + inputs.Add(tf.placeholder(input.dtype, shape: input.shape, name: "arg")); var outputs = map_func(inputs); func.ToGraph(inputs, outputs); func.Exit(); diff --git a/src/TensorFlowNET.Core/Functions/ConcreteFunction.cs b/src/TensorFlowNET.Core/Functions/ConcreteFunction.cs index 2aad3f39..1ee09a0a 100644 --- a/src/TensorFlowNET.Core/Functions/ConcreteFunction.cs +++ b/src/TensorFlowNET.Core/Functions/ConcreteFunction.cs @@ -36,7 +36,7 @@ namespace Tensorflow.Functions public ConcreteFunction(Func func, TF_DataType dtype) { - string func_name = $"{func.Method.Name}_{Guid.NewGuid()}"; + string func_name = $"{func.Method.Name}_{ops.uid_function()}"; func_graph = new FuncGraph(func_name); func_graph.as_default(); @@ -53,7 +53,7 @@ namespace Tensorflow.Functions public ConcreteFunction(Func func, TF_DataType dtype) { - string func_name = $"{func.Method.Name}_{Guid.NewGuid()}"; + string func_name = $"{func.Method.Name}_{ops.uid_function()}"; func_graph = new FuncGraph(func_name); func_graph.as_default(); @@ -74,7 +74,7 @@ namespace Tensorflow.Functions public ConcreteFunction(Func func, TF_DataType[] dtypes, TensorShape[] shapes) { - string func_name = $"{func.Method.Name}_{Guid.NewGuid()}"; + string func_name = $"{func.Method.Name}_{ops.uid_function()}"; // IntPtr func_handle; func_graph = new FuncGraph(func_name); diff --git a/src/TensorFlowNET.Core/Graphs/AutoGraph.cs b/src/TensorFlowNET.Core/Graphs/AutoGraph.cs index 0d938144..2af1a372 100644 --- a/src/TensorFlowNET.Core/Graphs/AutoGraph.cs +++ b/src/TensorFlowNET.Core/Graphs/AutoGraph.cs @@ -8,7 +8,7 @@ namespace Tensorflow.Graphs { public Func to_graph(Func func) { - string func_name = $"{func.Method.Name}_{Guid.NewGuid()}"; + string func_name = $"{func.Method.Name}_{ops.uid_function()}"; var graph = new FuncGraph(func_name); graph.as_default(); @@ -38,7 +38,7 @@ namespace Tensorflow.Graphs public Func to_graph(Func func) { - string func_name = $"{func.Method.Name}_{Guid.NewGuid()}"; + string func_name = $"{func.Method.Name}_{ops.uid_function()}"; var graph = new FuncGraph(func_name); graph.as_default(); diff --git a/src/TensorFlowNET.Core/Graphs/AutoGraphAttribute.cs b/src/TensorFlowNET.Core/Graphs/AutoGraphAttribute.cs index 9ffc7ea0..133c29a4 100644 --- a/src/TensorFlowNET.Core/Graphs/AutoGraphAttribute.cs +++ b/src/TensorFlowNET.Core/Graphs/AutoGraphAttribute.cs @@ -22,7 +22,7 @@ namespace Tensorflow.Graphs public override void OnEntry(MethodExecutionArgs args) { // TODO: func_name can be cache in FullName + Args - func_name = $"{args.Method.DeclaringType.FullName}.{args.Method.Name}_{Guid.NewGuid()}"; + func_name = $"{args.Method.DeclaringType.FullName}.{args.Method.Name}_{ops.uid_function()}"; if (functions.ContainsKey(func_name)) { diff --git a/src/TensorFlowNET.Core/ops.cs b/src/TensorFlowNET.Core/ops.cs index 68d6fdcf..8b2d04e7 100644 --- a/src/TensorFlowNET.Core/ops.cs +++ b/src/TensorFlowNET.Core/ops.cs @@ -353,6 +353,10 @@ namespace Tensorflow return Interlocked.Increment(ref uid_number); } + static int uid_number_for_function = 0; + public static int uid_function() + => Interlocked.Increment(ref uid_number_for_function); + public static void reset_uid() { uid_number = -1;