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.

BaseSession.cs 1.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace Tensorflow
  5. {
  6. public class BaseSession
  7. {
  8. private Graph _graph;
  9. private bool _opened;
  10. private bool _closed;
  11. private int _current_version;
  12. private byte[] _target;
  13. private IntPtr _session;
  14. public BaseSession(string target = "", Graph graph = null)
  15. {
  16. if(graph is null)
  17. {
  18. _graph = ops.get_default_graph();
  19. }
  20. else
  21. {
  22. _graph = graph;
  23. }
  24. _target = UTF8Encoding.UTF8.GetBytes(target);
  25. var opts = c_api.TF_NewSessionOptions();
  26. var status = new Status();
  27. _session = c_api.TF_NewSession(_graph.Handle, opts, status.Handle);
  28. c_api.TF_DeleteSessionOptions(opts);
  29. }
  30. public virtual byte[] run(Tensor fetches)
  31. {
  32. return _run(fetches);
  33. }
  34. private unsafe byte[] _run(Tensor fetches)
  35. {
  36. var status = new Status();
  37. c_api.TF_SessionRun(_session,
  38. run_options: null,
  39. inputs: new TF_Input[] { },
  40. input_values: new IntPtr[] { },
  41. ninputs: 1,
  42. outputs: new TF_Output[] { },
  43. output_values: new IntPtr[] { },
  44. noutputs: 1,
  45. target_opers: new IntPtr[] { },
  46. ntargets: 1,
  47. run_metadata: null,
  48. status: status.Handle);
  49. return null;
  50. }
  51. }
  52. }

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

Contributors (1)