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.

WhileContextTestCase.cs 1.7 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Microsoft.VisualStudio.TestTools.UnitTesting;
  6. using Tensorflow;
  7. using Tensorflow.Operations;
  8. namespace TensorFlowNET.UnitTest.control_flow_ops_test
  9. {
  10. [TestClass]
  11. public class WhileContextTestCase : PythonTest
  12. {
  13. private void _testWhileContextHelper(int? maximum_iterations = null)
  14. {
  15. // TODO: implement missing code dependencies
  16. with<Session>(this.cached_session(), sess =>
  17. {
  18. var i = constant_op.constant(0, name: "i");
  19. var c = new Func<Tensor, Tensor>(x => gen_math_ops.less(x, 10, name: "c"));
  20. var b = new Func<Tensor, Tensor>(x => gen_math_ops.add(x, 1, name: "c"));
  21. control_flow_ops.while_loop(
  22. c, b, new[] { i }, maximum_iterations);
  23. foreach (Operation op in sess.graph.get_operations())
  24. {
  25. var control_flow_context = op._get_control_flow_context();
  26. if (control_flow_context != null)
  27. self.assertProtoEquals(control_flow_context.to_proto(),
  28. WhileContext.from_proto(
  29. control_flow_context.to_proto()).to_proto());
  30. }
  31. });
  32. }
  33. [Ignore("TODO")]
  34. [TestMethod]
  35. public void testWhileContext()
  36. {
  37. _testWhileContextHelper();
  38. }
  39. [Ignore("TODO")]
  40. [TestMethod]
  41. public void testWhileContextWithMaximumIterations()
  42. {
  43. _testWhileContextHelper(maximum_iterations: 10);
  44. }
  45. }
  46. }

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