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.

Graph.cs 1.8 kB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.InteropServices;
  5. using System.Text;
  6. namespace TensorFlowNET.Core
  7. {
  8. /// <summary>
  9. /// TensorFlow uses a dataflow graph to represent your computation in terms of the dependencies between individual operations.
  10. /// This leads to a low-level programming model in which you first define the dataflow graph,
  11. /// then create a TensorFlow session to run parts of the graph across a set of local and remote devices.
  12. /// https://www.tensorflow.org/guide/graphs
  13. /// </summary>
  14. public class Graph
  15. {
  16. public IntPtr handle;
  17. private Dictionary<int, Operation> _nodes_by_id;
  18. private Dictionary<string, Operation> _nodes_by_name;
  19. public int _version;
  20. private int _next_id_counter;
  21. public Graph(IntPtr graph)
  22. {
  23. this.handle = graph;
  24. _nodes_by_id = new Dictionary<int, Operation>();
  25. _nodes_by_name = new Dictionary<string, Operation>();
  26. }
  27. public unsafe Operation create_op(string op_type, object inputs, TF_DataType[] dtypes, TF_DataType[] input_types = null, string name = "")
  28. {
  29. if (String.IsNullOrEmpty(name))
  30. {
  31. op_type = name;
  32. }
  33. var op = new Operation(this, inputs);
  34. op.name = name;
  35. return op;
  36. }
  37. public void _add_op(Operation op)
  38. {
  39. _nodes_by_id[op._id] = op;
  40. //_nodes_by_name[op.name] = op;
  41. _version = Math.Max(_version, op._id);
  42. }
  43. public int _next_id()
  44. {
  45. return ++_next_id_counter;
  46. }
  47. public Operation[] get_operations()
  48. {
  49. return _nodes_by_name.Values.Select(x => x).ToArray();
  50. }
  51. }
  52. }

tensorflow框架的.NET版本,提供了丰富的特性和API,可以借此很方便地在.NET平台下搭建深度学习训练与推理流程。

Contributors (1)