-
-
Notifications
You must be signed in to change notification settings - Fork 431
/
dcu_test.go
65 lines (47 loc) · 1.09 KB
/
dcu_test.go
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package gorgonia
import (
"io/ioutil"
"testing"
"gorgonia.org/tensor"
)
func TestBatchNormUnderstanding(t *testing.T) {
g := NewGraph()
xV := tensor.New(tensor.WithShape(2, 3, 2, 1), tensor.WithBacking([]float64{
0.0001,
0.003,
0.02,
0.007,
0.007,
0.05,
// ---
0.00015,
0.0035,
0.025,
0.0075,
0.0075,
0.055,
}))
x := NodeFromAny(g, xV, WithName("x"))
s2 := NewTensor(g, x.Dtype(), x.Shape().Dims(), WithShape(x.Shape().Clone()...), WithInit(Ones()), WithName("Scale"))
b2 := NewTensor(g, x.Dtype(), x.Shape().Dims(), WithShape(x.Shape().Clone()...), WithInit(Zeroes()), WithName("Bias"))
y2, scale2, bias2, op2, err := BatchNorm(x, s2, b2, 0.1, 1e-05)
if err != nil {
t.Fatal(err)
}
WithName("y2")(y2)
op2.SetTraining(true)
C, _ := Sum(y2)
_, err = Grad(C, x, scale2, bias2)
if err != nil {
t.Fatal(err)
}
m := NewTapeMachine(g, TraceExec())
if err := m.RunAll(); err != nil {
t.Fatal(err)
}
ioutil.WriteFile("foo.dot", []byte(g.ToDot()), 0644)
t.Logf("\n%v", y2.Value())
// _, _ = scale, scale2
// _, _ = bias, bias2
// _, _ = op, op2
}