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.

c_test_util.cs 1.2 kB

12345678910111213141516171819202122232425262728293031323334353637
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Runtime.InteropServices;
  4. using System.Text;
  5. using Tensorflow;
  6. namespace TensorFlowNET.UnitTest
  7. {
  8. public static class c_test_util
  9. {
  10. public static void ConstHelper(Tensor t, Graph graph, Status s, string name, ref IntPtr op)
  11. {
  12. var desc = c_api.TF_NewOperation(graph, "Const", name);
  13. c_api.TF_SetAttrTensor(desc, "value", t.Handle, s);
  14. s.Check();
  15. c_api.TF_SetAttrType(desc, "dtype", t.dtype);
  16. op = c_api.TF_FinishOperation(desc, s);
  17. s.Check();
  18. if(op == null)
  19. {
  20. throw new Exception("c_api.TF_FinishOperation failed.");
  21. }
  22. }
  23. public static Operation Const(Tensor t, Graph graph, Status s, string name)
  24. {
  25. IntPtr op = IntPtr.Zero;
  26. ConstHelper(t, graph, s, name, ref op);
  27. return new Operation(op);
  28. }
  29. public static Operation ScalarConst(int v, Graph graph, Status s, string name = "Const")
  30. {
  31. return Const(new Tensor(v), graph, s, name);
  32. }
  33. }
  34. }

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

Contributors (1)