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.

GradientEagerTest.cs 779 B

12345678910111213141516171819202122232425262728
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Microsoft.VisualStudio.TestTools.UnitTesting;
  5. using Tensorflow;
  6. using static Tensorflow.Binding;
  7. namespace TensorFlowNET.UnitTest.Gradient
  8. {
  9. [TestClass]
  10. public class GradientEagerTest : PythonTest
  11. {
  12. [Ignore]
  13. [TestMethod]
  14. public void ConstantSq()
  15. {
  16. // Calcute the gradient of w * w
  17. // by Automatic Differentiation in Eager mode
  18. // in tensorflow.net 2.x that is in development intensively
  19. var w = tf.constant(1.5f);
  20. using var tape = tf.GradientTape();
  21. tape.watch(w);
  22. var loss = w * w;
  23. var grad = tape.gradient(loss, w);
  24. print(grad);
  25. }
  26. }
  27. }