public ConcreteFunction(Func <Tensor, Tensor> func, TF_DataType dtype) { string func_name = $"{func.Method.Name}_{ops.uid_function()}"; func_graph = new FuncGraph(func_name); func_graph.as_default(); var input = tf.placeholder(dtype); var output = func(input); var opers = func_graph._nodes_by_name.Values.Select(x => x as Operation).ToArray(); func_graph.ToGraph(opers, new[] { input }, new[] { output }, null); func_graph.Exit(); }
public ConcreteFunction(Func <Tensor, IDatasetV2> func, TF_DataType dtype) { string func_name = $"{func.Method.Name}_{Guid.NewGuid()}"; func_graph = new FuncGraph(func_name); func_graph.as_default(); var input = tf.placeholder(dtype); var output = func(input); OutputStructure = output.structure; var opers = func_graph._nodes_by_name.Values.Select(x => x as Operation).ToArray(); func_graph.ToGraph(opers, new[] { input }, new[] { output.variant_tensor }, null); func_graph.Exit(); }
public ConcreteFunction(Func <Tensors, Tensors> func, TF_DataType[] dtypes, TensorShape[] shapes) { string func_name = $"{func.Method.Name}_{Guid.NewGuid()}"; // IntPtr func_handle; using var graph = new FuncGraph(func_name); graph.as_default(); var inputs = new Tensors(); foreach (var(i, dtype) in enumerate(dtypes)) { inputs.Add(tf.placeholder(dtypes[i], shape: shapes[i], name: "args")); } Outputs = func(inputs); OutputStructure = Outputs.Select(x => x.ToTensorSpec()).ToArray(); var opers = graph._nodes_by_name.Values.Select(x => x as Operation).ToArray(); _handle = graph.ToGraph(opers, inputs, Outputs, null); graph.Exit(); }
public void Exit() { func_graph.Exit(); }