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

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using System;
  2. using Microsoft.VisualStudio.TestTools.UnitTesting;
  3. using Tensorflow;
  4. using static Tensorflow.Binding;
  5. namespace TensorFlowNET.UnitTest
  6. {
  7. [TestClass]
  8. public class NameScopeTest
  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 NestedNameScope_Using()
  39. {
  40. Graph g = tf.Graph().as_default();
  41. using (var name = new ops.NameScope("scope1"))
  42. {
  43. Assert.AreEqual("scope1", g._name_stack);
  44. Assert.AreEqual("scope1/", name);
  45. var const1 = tf.constant(1.0);
  46. Assert.AreEqual("scope1/Const:0", const1.name);
  47. using (var name2 = new ops.NameScope("scope2"))
  48. {
  49. Assert.AreEqual("scope1/scope2", g._name_stack);
  50. Assert.AreEqual("scope1/scope2/", name);
  51. var const2 = tf.constant(2.0);
  52. Assert.AreEqual("scope1/scope2/Const:0", const2.name);
  53. }
  54. Assert.AreEqual("scope1", g._name_stack);
  55. var const3 = tf.constant(2.0);
  56. Assert.AreEqual("scope1/Const_1:0", const3.name);
  57. }
  58. ;
  59. g.Dispose();
  60. Assert.AreEqual("", g._name_stack);
  61. }
  62. }
  63. }