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.

ops.name_scope.cs 1.7 kB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using Tensorflow.Eager;
  5. namespace Tensorflow
  6. {
  7. public partial class ops
  8. {
  9. public class name_scope : IPython
  10. {
  11. public string _name;
  12. public string _default_name;
  13. public object _values;
  14. public Context _ctx;
  15. public string _name_scope;
  16. public string old_stack = "";
  17. private object _g_manager;
  18. public name_scope(string name, string default_name = "", object values = null)
  19. {
  20. _name = name;
  21. _default_name = default_name;
  22. _values = values;
  23. // _ctx = new Context();
  24. }
  25. public void __enter__()
  26. {
  27. if (String.IsNullOrEmpty(_name))
  28. {
  29. _name = _default_name;
  30. }
  31. Graph g = null;
  32. if (_values is List<Tensor> values)
  33. g = _get_graph_from_inputs(values);
  34. if (g == null)
  35. g = get_default_graph();
  36. old_stack = g._name_stack;
  37. _name_scope = g.name_scope(_name);
  38. }
  39. public void Dispose()
  40. {
  41. var g = get_default_graph();
  42. g._name_stack = old_stack;
  43. }
  44. public void __exit__()
  45. {
  46. }
  47. /// <summary>
  48. /// __enter__()
  49. /// </summary>
  50. /// <param name="ns"></param>
  51. public static implicit operator string(name_scope ns)
  52. {
  53. return ns._name_scope;
  54. }
  55. }
  56. }
  57. }

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