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
123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. using Tensorflow;
  6. namespace TensorFlowNET.UnitTest
  7. {
  8. [TestClass]
  9. public class NameScopeTest : Python
  10. {
  11. Graph g = ops.get_default_graph();
  12. string name = "";
  13. [TestMethod]
  14. public void NestedNameScope()
  15. {
  16. with<ops.name_scope>(new ops.name_scope("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. with<ops.name_scope>(new ops.name_scope("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. Assert.AreEqual("", g._name_stack);
  36. }
  37. }
  38. }

tensorflow框架的.NET版本,提供了丰富的特性和API,可以借此很方便地在.NET平台下搭建深度学习训练与推理流程。