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.4 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using Tensorflow;
  3. using static Tensorflow.Binding;
  4. namespace TensorFlowNET.UnitTest.Basics
  5. {
  6. [TestClass]
  7. public class NameScopeTest : GraphModeTestBase
  8. {
  9. string name = "";
  10. [TestMethod]
  11. public void NestedNameScope()
  12. {
  13. Graph g = tf.Graph().as_default();
  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. g.Dispose();
  34. Assert.AreEqual("", g._name_stack);
  35. }
  36. [TestMethod, Ignore("Unimplemented Usage")]
  37. public void NestedNameScope_Using()
  38. {
  39. Graph g = tf.Graph().as_default();
  40. using (var name = new ops.NameScope("scope1"))
  41. {
  42. Assert.AreEqual("scope1", g._name_stack);
  43. Assert.AreEqual("scope1/", name);
  44. var const1 = tf.constant(1.0);
  45. Assert.AreEqual("scope1/Const:0", const1.name);
  46. using (var name2 = new ops.NameScope("scope2"))
  47. {
  48. Assert.AreEqual("scope1/scope2", g._name_stack);
  49. Assert.AreEqual("scope1/scope2/", name);
  50. var const2 = tf.constant(2.0);
  51. Assert.AreEqual("scope1/scope2/Const:0", const2.name);
  52. }
  53. Assert.AreEqual("scope1", g._name_stack);
  54. var const3 = tf.constant(2.0);
  55. Assert.AreEqual("scope1/Const_1:0", const3.name);
  56. };
  57. g.Dispose();
  58. Assert.AreEqual("", g._name_stack);
  59. }
  60. }
  61. }