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

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using Tensorflow;
  3. using static Tensorflow.Python;
  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. }
  38. }