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.

Status.cs 1.4 kB

6 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace Tensorflow
  5. {
  6. /// <summary>
  7. /// TF_Status holds error information. It either has an OK code, or
  8. /// else an error code with an associated error message.
  9. /// </summary>
  10. public class Status
  11. {
  12. private readonly IntPtr _handle;
  13. /// <summary>
  14. /// Error message
  15. /// </summary>
  16. public string Message => c_api.StringPiece(c_api.TF_Message(_handle));
  17. /// <summary>
  18. /// Error code
  19. /// </summary>
  20. public TF_Code Code => c_api.TF_GetCode(_handle);
  21. public Status()
  22. {
  23. _handle = c_api.TF_NewStatus();
  24. }
  25. public void SetStatus(TF_Code code, string msg)
  26. {
  27. c_api.TF_SetStatus(_handle, code, msg);
  28. }
  29. /// <summary>
  30. /// Check status
  31. /// Throw exception with error message if code != TF_OK
  32. /// </summary>
  33. public void Check()
  34. {
  35. if(Code != TF_Code.TF_OK)
  36. {
  37. Console.WriteLine(Message);
  38. // throw new Exception(Message);
  39. }
  40. }
  41. public static implicit operator IntPtr(Status status)
  42. {
  43. return status._handle;
  44. }
  45. public void Dispose()
  46. {
  47. c_api.TF_DeleteStatus(_handle);
  48. }
  49. }
  50. }

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

Contributors (1)