Browse Source

uid_function for func_name

tags/v0.40-tf2.4-tstring
Oceania2018 4 years ago
parent
commit
a814d2d9ee
5 changed files with 12 additions and 8 deletions
  1. +2
    -2
      src/TensorFlowNET.Core/Data/MapDataset.cs
  2. +3
    -3
      src/TensorFlowNET.Core/Functions/ConcreteFunction.cs
  3. +2
    -2
      src/TensorFlowNET.Core/Graphs/AutoGraph.cs
  4. +1
    -1
      src/TensorFlowNET.Core/Graphs/AutoGraphAttribute.cs
  5. +4
    -0
      src/TensorFlowNET.Core/ops.cs

+ 2
- 2
src/TensorFlowNET.Core/Data/MapDataset.cs View File

@@ -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();


+ 3
- 3
src/TensorFlowNET.Core/Functions/ConcreteFunction.cs View File

@@ -36,7 +36,7 @@ namespace Tensorflow.Functions

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();
@@ -53,7 +53,7 @@ namespace Tensorflow.Functions

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();
@@ -74,7 +74,7 @@ namespace Tensorflow.Functions
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);


+ 2
- 2
src/TensorFlowNET.Core/Graphs/AutoGraph.cs View File

@@ -8,7 +8,7 @@ namespace Tensorflow.Graphs
{
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();
@@ -38,7 +38,7 @@ namespace Tensorflow.Graphs

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();


+ 1
- 1
src/TensorFlowNET.Core/Graphs/AutoGraphAttribute.cs View File

@@ -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))
{


+ 4
- 0
src/TensorFlowNET.Core/ops.cs View File

@@ -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;


Loading…
Cancel
Save