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 System;
  2. using Microsoft.VisualStudio.TestTools.UnitTesting;
  3. using Tensorflow;
  4. using Tensorflow.UnitTest;
  5. using static Tensorflow.Binding;
  6. namespace TensorFlowNET.UnitTest.Basics
  7. {
  8. [TestClass]
  9. public class NameScopeTest : GraphModeTestBase
  10. {
  11. string name = "";
  12. [TestMethod]
  13. public void NestedNameScope()
  14. {
  15. Graph g = tf.Graph().as_default();
  16. tf_with(new ops.NameScope("scope1"), scope1 =>
  17. {
  18. name = scope1;
  19. Assert.AreEqual("scope1", g._name_stack);
  20. Assert.AreEqual("scope1/", name);
  21. var const1 = tf.constant(1.0);
  22. Assert.AreEqual("scope1/Const:0", const1.name);
  23. tf_with(new ops.NameScope("scope2"), scope2 =>
  24. {
  25. name = scope2;
  26. Assert.AreEqual("scope1/scope2", g._name_stack);
  27. Assert.AreEqual("scope1/scope2/", name);
  28. var const2 = tf.constant(2.0);
  29. Assert.AreEqual("scope1/scope2/Const:0", const2.name);
  30. });
  31. Assert.AreEqual("scope1", g._name_stack);
  32. var const3 = tf.constant(2.0);
  33. Assert.AreEqual("scope1/Const_1:0", const3.name);
  34. });
  35. g.Dispose();
  36. Assert.AreEqual("", g._name_stack);
  37. }
  38. [TestMethod]
  39. public void NameScopeInEagerMode()
  40. {
  41. tf.enable_eager_execution();
  42. tf_with(new ops.NameScope("scope"), scope =>
  43. {
  44. string name = scope;
  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. }