You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

EagerDefinedFunction.cs 1.3 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using Google.Protobuf;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using Tensorflow.Graphs;
  7. using static Tensorflow.Binding;
  8. namespace Tensorflow.Functions
  9. {
  10. public class EagerDefinedFunction
  11. {
  12. public int _num_outputs;
  13. public string Name => _func_graph.FuncName;
  14. FuncGraph _func_graph;
  15. public EagerDefinedFunction(string name, FuncGraph graph,
  16. Tensors inputs, Tensors outputs,
  17. Dictionary<string, string> attrs)
  18. {
  19. _num_outputs = outputs.Length;
  20. var input_ops = inputs.Select(x => x.op).ToArray();
  21. var operations = graph.get_operations().Where(x => !input_ops.Contains(x.op))
  22. .Select(x => x as Operation).ToArray();
  23. var output_names = new string[0];
  24. _func_graph = new FuncGraph(graph, name, attrs);
  25. _func_graph.ToGraph(operations, inputs, outputs, output_names);
  26. }
  27. public Tensors Call(Tensors args)
  28. {
  29. var results = tf.Runner.TFE_Execute(tf.Context,
  30. tf.Context.DeviceName,
  31. _func_graph.FuncName,
  32. args,
  33. null,
  34. _num_outputs);
  35. return results;
  36. }
  37. }
  38. }