-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlayer_bwdfilt.go
More file actions
209 lines (188 loc) · 3.7 KB
/
layer_bwdfilt.go
File metadata and controls
209 lines (188 loc) · 3.7 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
package gocunets
import (
"errors"
"github.com/dereklstinson/gocunets/layers"
//"github.com/dereklstinson/gocunets/layers"
)
func (l *Layer) backpropfilter() error {
// return l.h.w.Work(func() error {
var err error
x, dx, y, dy := l.x.Tensor, l.dx.Tensor, l.y.Tensor, l.dy.Tensor
if l.cnn != nil {
err = l.cnn.BackPropFilter(l.h.Handler, l.workspacebwf, x, y)
if err != nil {
println("bpfd error in cnn")
return err
}
return nil
}
if l.activation != nil {
if l.activation.ContainsWeights() {
err = l.activation.BackProp(l.h.Handler, x, dx, y, dy)
if err != nil {
println("bpfd error in activation")
return err
}
}
return nil
}
if l.drop != nil {
/*
err = l.drop.BackProp(handle, x, y)
if err != nil {
println("bpfd error in drop")
return err
}
*/
return nil
}
if l.pool != nil {
/*
err = l.pool.BackProp(handle, x, y)
if err != nil {
println("bpfd error in pool")
return err
}
*/
return nil
}
if l.reshape != nil {
/*
err = l.reshape.BackProp(handle, x, y)
if err != nil {
println("bpfd error in reshape")
return err
}
*/
return nil
}
if l.batch != nil {
/*
err = l.batch.BackProp(handle, x, y)
if err != nil {
println("bpfd error in batch")
return err
}
*/
return nil
}
if l.cnntranspose != nil {
err = l.cnntranspose.BackPropFilter(l.h.Handler, l.workspacebwd, x, y)
if err != nil {
println("bpfd error in cnntranspose")
return err
}
return nil
}
return errors.New("Layer Not Set Up")
//})
}
//BackProp does the backprop of a layer
func (l *Layer) backpropfilterdata() error {
//return l.h.w.Work(func() error {
err := l.h.Sync()
if err != nil {
return err
}
var x, dx, y, dy *layers.Tensor
if l.dx != nil {
dx = l.dx.Tensor
} else {
dx = nil
}
if l.x != nil {
x = l.x.Tensor
}
if l.dy != nil {
dy = l.dy.Tensor
}
if l.y != nil {
y = l.y.Tensor
}
wspacedata, wspacefilter := l.workspacebwd, l.workspacebwf
if l.cnn != nil {
err = l.cnn.BackPropFilterData(l.h.Handler, wspacedata, wspacefilter, x, dx, dy)
if err != nil {
println("bpfd error in cnn")
return err
}
err = l.h.Sync()
if err != nil {
println("bpfd error in cnn sync")
}
return nil
}
if l.activation != nil {
err = l.activation.BackProp(l.h.Handler, x, dx, y, dy)
if err != nil {
println("bpfd error in activation")
return err
}
err = l.h.Sync()
if err != nil {
println("bpfd error in activation sync")
}
return nil
}
if l.drop != nil {
err = l.drop.BackProp(l.h.Handler, x, y)
if err != nil {
println("bpfd error in drop")
return err
}
err = l.h.Sync()
if err != nil {
println("bpfd error in drop sync")
}
return nil
}
if l.pool != nil {
err = l.pool.BackProp(l.h.Handler, x, dx, y, dy)
if err != nil {
println("bpfd error in pool")
return err
}
err = l.h.Sync()
if err != nil {
println("bpfd error in pool sync")
}
return nil
}
if l.reshape != nil {
err = l.reshape.BackProp(l.h.Handler, x, y)
if err != nil {
println("bpfd error in reshape")
return err
}
err = l.h.Sync()
if err != nil {
println("bpfd error in reshape sync")
}
return nil
}
if l.batch != nil {
err = l.batch.BackProp(l.h.Handler, x, dx, dy)
if err != nil {
println("bpfd error in batch")
return err
}
err = l.h.Sync()
if err != nil {
println("bpfd error in batch sync")
}
return nil
}
if l.cnntranspose != nil {
err = l.cnntranspose.BackPropFilterData(l.h.Handler, wspacedata, wspacefilter, x, dx, dy)
if err != nil {
return err
}
err = l.h.Sync()
if err != nil {
println("bpfd error in cnntranspose sync")
}
return nil
}
return errors.New("Layer Not Set Up")
// })
}