forked from SciSharp/TensorFlow.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGradientTest.cs
More file actions
32 lines (29 loc) · 1012 Bytes
/
GradientTest.cs
File metadata and controls
32 lines (29 loc) · 1012 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Text;
using Tensorflow;
namespace TensorFlowNET.UnitTest
{
[TestClass]
public class GradientTest
{
[TestMethod]
public void Gradients()
{
var graph = tf.Graph().as_default();
var a = tf.constant(0.0);
var b = 2.0 * a;
Assert.AreEqual(b.name, "mul:0");
Assert.AreEqual(b.op.inputs[0].name, "mul/x:0");
Assert.AreEqual(b.op.inputs[1].name, "Const:0");
var ys = a + b;
Assert.AreEqual(ys.name, "add:0");
Assert.AreEqual(ys.op.inputs[0].name, "Const:0");
Assert.AreEqual(ys.op.inputs[1].name, "mul:0");
var g = tf.gradients(ys, new Tensor[] { a, b }, stop_gradients: new Tensor[] { a, b });
Assert.AreEqual(g[0].name, "gradients/Fill:0");
Assert.AreEqual(g[1].name, "gradients/Fill:0");
}
}
}