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.

GraphTest.cs 1.9 kB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. [TestClass]
  9. public class GraphTest
  10. {
  11. /// <summary>
  12. /// Port from c_api_test.cc
  13. /// `TEST(CAPI, Graph)`
  14. /// </summary>
  15. [TestMethod]
  16. public void c_api_Graph()
  17. {
  18. var s = new Status();
  19. var graph = new Graph();
  20. // Make a placeholder operation.
  21. var feed = c_test_util.Placeholder(graph, s);
  22. Assert.AreEqual("feed", feed.name);
  23. Assert.AreEqual("Placeholder", feed.optype);
  24. Assert.AreEqual("", feed.device);
  25. Assert.AreEqual(1, feed.NumOutputs);
  26. Assert.AreEqual(TF_DataType.TF_INT32, feed.OutputType);
  27. Assert.AreEqual(1, feed.OutputListLength);
  28. Assert.AreEqual(0, feed.NumInputs);
  29. Assert.AreEqual(0, feed.NumConsumers);
  30. Assert.AreEqual(0, feed.NumControlInputs);
  31. Assert.AreEqual(0, feed.NumControlOutputs);
  32. AttrValue attr_value = null;
  33. c_test_util.GetAttrValue(feed, "dtype", ref attr_value, s);
  34. Assert.AreEqual(attr_value.Type, DataType.DtInt32);
  35. // Test not found errors in TF_Operation*() query functions.
  36. // Assert.AreEqual(-1, c_api.TF_OperationOutputListLength(feed, "bogus", s));
  37. // Assert.AreEqual(TF_Code.TF_INVALID_ARGUMENT, s.Code);
  38. // Assert.IsFalse(c_test_util.GetAttrValue(feed, "missing", ref attr_value, s));
  39. // Assert.AreEqual("Operation 'feed' has no attr named 'missing'.", s.Message);
  40. // Make a constant oper with the scalar "3".
  41. var three = c_test_util.ScalarConst(3, graph, s);
  42. // Add oper.
  43. var add = c_test_util.Add(feed, three, graph, s);
  44. }
  45. }
  46. }

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

Contributors (1)