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 2.8 kB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using Tensorflow;
  3. using Tensorflow.UnitTest;
  4. using static Tensorflow.Binding;
  5. namespace TensorFlowNET.UnitTest.Basics
  6. {
  7. [TestClass]
  8. public class NameScopeTest : GraphModeTestBase
  9. {
  10. string name = "";
  11. [TestMethod]
  12. public void NestedNameScope()
  13. {
  14. Graph g = tf.Graph().as_default();
  15. tf_with(new ops.NameScope("scope1"), scope1 =>
  16. {
  17. name = scope1;
  18. Assert.AreEqual("scope1", g._name_stack);
  19. Assert.AreEqual("scope1/", name);
  20. var const1 = tf.constant(1.0);
  21. Assert.AreEqual("scope1/Const:0", const1.name);
  22. tf_with(new ops.NameScope("scope2"), scope2 =>
  23. {
  24. name = scope2;
  25. Assert.AreEqual("scope1/scope2", g._name_stack);
  26. Assert.AreEqual("scope1/scope2/", name);
  27. var const2 = tf.constant(2.0);
  28. Assert.AreEqual("scope1/scope2/Const:0", const2.name);
  29. });
  30. Assert.AreEqual("scope1", g._name_stack);
  31. var const3 = tf.constant(2.0);
  32. Assert.AreEqual("scope1/Const_1:0", const3.name);
  33. });
  34. g.Dispose();
  35. Assert.AreEqual("", g._name_stack);
  36. }
  37. [TestMethod]
  38. public void NameScopeInEagerMode()
  39. {
  40. tf.enable_eager_execution();
  41. tf_with(new ops.NameScope("scope"), scope =>
  42. {
  43. string name = scope;
  44. var const1 = tf.constant(1.0);
  45. });
  46. tf.compat.v1.disable_eager_execution();
  47. }
  48. [TestMethod, Ignore("Unimplemented Usage")]
  49. public void NestedNameScope_Using()
  50. {
  51. Graph g = tf.Graph().as_default();
  52. using (var name = new ops.NameScope("scope1"))
  53. {
  54. Assert.AreEqual("scope1", g._name_stack);
  55. Assert.AreEqual("scope1/", name);
  56. var const1 = tf.constant(1.0);
  57. Assert.AreEqual("scope1/Const:0", const1.name);
  58. using (var name2 = new ops.NameScope("scope2"))
  59. {
  60. Assert.AreEqual("scope1/scope2", g._name_stack);
  61. Assert.AreEqual("scope1/scope2/", name);
  62. var const2 = tf.constant(2.0);
  63. Assert.AreEqual("scope1/scope2/Const:0", const2.name);
  64. }
  65. Assert.AreEqual("scope1", g._name_stack);
  66. var const3 = tf.constant(2.0);
  67. Assert.AreEqual("scope1/Const_1:0", const3.name);
  68. };
  69. g.Dispose();
  70. Assert.AreEqual("", g._name_stack);
  71. }
  72. }
  73. }