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 762 B

123456789101112131415161718192021222324252627
  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. [TestMethod]
  13. public void ConstantSq()
  14. {
  15. // Calcute the gradient of w * w
  16. // by Automatic Differentiation in Eager mode
  17. // in tensorflow.net 2.x that is in development intensively
  18. var w = tf.constant(1.5f);
  19. using var tape = tf.GradientTape();
  20. tape.watch(w);
  21. var loss = w * w;
  22. var grad = tape.gradient(loss, w);
  23. print(grad);
  24. }
  25. }
  26. }