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.

Buffer.cs 1.1 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Runtime.InteropServices;
  4. using System.Text;
  5. namespace Tensorflow
  6. {
  7. public class Buffer : IDisposable
  8. {
  9. private IntPtr _handle;
  10. private TF_Buffer buffer => Marshal.PtrToStructure<TF_Buffer>(_handle);
  11. public byte[] Data
  12. {
  13. get
  14. {
  15. var data = new byte[buffer.length];
  16. if (buffer.length > 0)
  17. Marshal.Copy(buffer.data, data, 0, (int)buffer.length);
  18. return data;
  19. }
  20. }
  21. public int Length => (int)buffer.length;
  22. public Buffer()
  23. {
  24. _handle = c_api.TF_NewBuffer();
  25. }
  26. public Buffer(IntPtr handle)
  27. {
  28. _handle = handle;
  29. }
  30. public static implicit operator IntPtr(Buffer buffer)
  31. {
  32. return buffer._handle;
  33. }
  34. public static implicit operator byte[](Buffer buffer)
  35. {
  36. return buffer.Data;
  37. }
  38. public void Dispose()
  39. {
  40. c_api.TF_DeleteBuffer(_handle);
  41. }
  42. }
  43. }

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

Contributors (1)