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.

ControlDependenciesTest.cs 1.3 kB

1234567891011121314151617181920212223242526272829303132333435363738
  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. namespace TensorFlowNET.UnitTest
  8. {
  9. /// <summary>
  10. /// tensorflow/python/framework/ops_test.py
  11. /// </summary>
  12. [TestClass]
  13. public class ControlDependenciesTest : Python
  14. {
  15. [TestMethod]
  16. public void TestBasic()
  17. {
  18. var graph = tf.Graph().as_default();
  19. Tensor a=null, b = null, c = null, d = null, e = null;
  20. with<Graph>(graph, g =>
  21. {
  22. a = constant_op.constant(1.0);
  23. b = constant_op.constant(1.0);
  24. with(g.control_dependencies(new ITensorOrOperation[] {a}), x =>
  25. {
  26. c = constant_op.constant(1.0);
  27. d = array_ops.identity(b);
  28. e = array_ops.identity(c);
  29. });
  30. });
  31. Assert.IsTrue(Enumerable.SequenceEqual(c.op.control_inputs, new[] {a.op}));
  32. Assert.IsTrue(Enumerable.SequenceEqual(d.op.control_inputs, new[] {a.op}));
  33. // e should be dominated by c.
  34. Assert.AreEqual(0, e.op.control_inputs.Length);
  35. }
  36. }
  37. }

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