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.

CApiAttributesTestcs.cs 2.7 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. using Tensorflow;
  6. namespace TensorFlowNET.UnitTest
  7. {
  8. /// <summary>
  9. /// tensorflow\c\c_api_test.cc
  10. /// `class CApiAttributesTest`
  11. /// </summary>
  12. [TestClass]
  13. public class CApiAttributesTestcs : CApiTest, IDisposable
  14. {
  15. private Graph graph_;
  16. private int counter_;
  17. private Status s_;
  18. public CApiAttributesTestcs()
  19. {
  20. s_ = new Status();
  21. graph_ = new Graph();
  22. }
  23. private OperationDescription init(string type)
  24. {
  25. // Construct op_name to match the name used by REGISTER_OP in the
  26. // ATTR_TEST_REGISTER calls above.
  27. string op_name = "CApiAttributesTestOp";
  28. if (type.Contains("list("))
  29. {
  30. op_name += "List";
  31. type = type.Substring(5, type.Length - 6);
  32. }
  33. op_name += type;
  34. return c_api.TF_NewOperation(graph_, op_name, $"name{counter_++}");
  35. }
  36. /// <summary>
  37. /// REGISTER_OP for CApiAttributesTest test cases.
  38. /// Registers two ops, each with a single attribute called 'v'.
  39. /// The attribute in one op will have a type 'type', the other
  40. /// will have list(type).
  41. /// </summary>
  42. /// <param name="type"></param>
  43. private void ATTR_TEST_REGISTER_OP(string type)
  44. {
  45. }
  46. private void EXPECT_TF_META(Operation oper, string attr_name, int expected_list_size, TF_AttrType expected_type, uint expected_total_size)
  47. {
  48. var m = c_api.TF_OperationGetAttrMetadata(oper, attr_name, s_);
  49. EXPECT_EQ(TF_Code.TF_OK, s_.Code);
  50. char e = expected_list_size >= 0 ? (char)1 : (char)0;
  51. /*EXPECT_EQ(e, m.is_list);
  52. EXPECT_EQ(expected_list_size, m.list_size);
  53. EXPECT_EQ(expected_type, m.type);
  54. EXPECT_EQ(expected_total_size, m.total_size);*/
  55. }
  56. [TestMethod]
  57. public void String()
  58. {
  59. //var desc = init("string");
  60. //c_api.TF_SetAttrString(desc, "v", "bunny", 5);
  61. //var oper = c_api.TF_FinishOperation(desc, s_);
  62. //ASSERT_EQ(TF_Code.TF_OK, s_.Code);
  63. //EXPECT_TF_META(oper, "v", -1, TF_AttrType.TF_ATTR_STRING, 5);
  64. //var value = new char[5];
  65. //c_api.TF_OperationGetAttrString(oper, "v", value, 5, s_);
  66. //EXPECT_EQ(TF_Code.TF_OK, s_.Code);
  67. //EXPECT_EQ("bunny", value, 5));
  68. }
  69. public void Dispose()
  70. {
  71. graph_.Dispose();
  72. s_.Dispose();
  73. }
  74. }
  75. }

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