Skip to content

Commit

Permalink
uid_function for func_name
Browse files Browse the repository at this point in the history
  • Loading branch information
Oceania2018 committed Mar 14, 2021
1 parent 827d8f2 commit a814d2d
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/TensorFlowNET.Core/Data/MapDataset.cs
Expand Up @@ -15,11 +15,11 @@ public class MapDataset : UnaryDataset
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();
Expand Down
6 changes: 3 additions & 3 deletions src/TensorFlowNET.Core/Functions/ConcreteFunction.cs
Expand Up @@ -36,7 +36,7 @@ public ConcreteFunction(FuncGraph graph, Dictionary<string, string> attrs = null

public ConcreteFunction(Func<Tensor, Tensor> 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();
Expand All @@ -53,7 +53,7 @@ public ConcreteFunction(Func<Tensor, Tensor> func, TF_DataType dtype)

public ConcreteFunction(Func<Tensor, IDatasetV2> 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();
Expand All @@ -74,7 +74,7 @@ public ConcreteFunction(Func<Tensor, IDatasetV2> func, TF_DataType dtype)
public ConcreteFunction(Func<Tensors, Tensors> 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);
Expand Down
4 changes: 2 additions & 2 deletions src/TensorFlowNET.Core/Graphs/AutoGraph.cs
Expand Up @@ -8,7 +8,7 @@ public class AutoGraph
{
public Func<Tensor, Tensor> to_graph(Func<Tensor, Tensor> 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();
Expand Down Expand Up @@ -38,7 +38,7 @@ public class AutoGraph

public Func<Tensor, Tensor, Tensor> to_graph(Func<Tensor, Tensor, Tensor> 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();
Expand Down
2 changes: 1 addition & 1 deletion src/TensorFlowNET.Core/Graphs/AutoGraphAttribute.cs
Expand Up @@ -22,7 +22,7 @@ public sealed class AutoGraphAttribute : OnMethodBoundaryAspect
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))
{
Expand Down
4 changes: 4 additions & 0 deletions src/TensorFlowNET.Core/ops.cs
Expand Up @@ -353,6 +353,10 @@ public static int uid()
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;
Expand Down

0 comments on commit a814d2d

Please sign in to comment.