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.

NameScopeTest.cs 1.3 kB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using Tensorflow;
  3. using static Tensorflow.Python;
  4. namespace TensorFlowNET.UnitTest
  5. {
  6. [TestClass]
  7. public class NameScopeTest
  8. {
  9. Graph g = ops.get_default_graph();
  10. string name = "";
  11. [TestMethod]
  12. public void NestedNameScope()
  13. {
  14. tf_with(new ops.NameScope("scope1"), scope1 =>
  15. {
  16. name = scope1;
  17. Assert.AreEqual("scope1", g._name_stack);
  18. Assert.AreEqual("scope1/", name);
  19. var const1 = tf.constant(1.0);
  20. Assert.AreEqual("scope1/Const:0", const1.name);
  21. tf_with(new ops.NameScope("scope2"), scope2 =>
  22. {
  23. name = scope2;
  24. Assert.AreEqual("scope1/scope2", g._name_stack);
  25. Assert.AreEqual("scope1/scope2/", name);
  26. var const2 = tf.constant(2.0);
  27. Assert.AreEqual("scope1/scope2/Const:0", const2.name);
  28. });
  29. Assert.AreEqual("scope1", g._name_stack);
  30. var const3 = tf.constant(2.0);
  31. Assert.AreEqual("scope1/Const_1:0", const3.name);
  32. });
  33. Assert.AreEqual("", g._name_stack);
  34. }
  35. }
  36. }