提交 c38f534f authored 作者: Alexander Matyasko's avatar Alexander Matyasko

Update numpy implementation of PoolRop

Implements max pooling rop which works with both stride and padding. Both variables can be symbolic. Also defined Rop for average and sum pooling. For average or sum, Rop is simply op called on eval_points.
上级 ad1310c8
......@@ -21,6 +21,7 @@ import numpy
from theano.gof import Op, Apply
from theano.gradient import grad_undefined
from theano.tests.unittest_tools import SkipTest
from theano.tensor.signal.pool import Pool
from theano.tensor.nnet import conv, conv2d
'''
......@@ -255,6 +256,28 @@ class test_RopLop(RopLop_checker):
self.x[:4].dimshuffle('x', 0), 0).sum(axis=1),
(1,))
def test_downsample(self):
rng = numpy.random.RandomState(utt.fetch_seed())
test_ws = ((1, 1), (3, 2), (2, 3))
vx = (rng.rand(2, 3, 3, 4) * 2.0).astype(theano.config.floatX)
vv = (rng.rand(2, 3, 3, 4) * 2.0).astype(theano.config.floatX)
input = theano.shared(vx)
eval_p = theano.shared(vv)
for ws in test_ws:
for ignore_border in [False, True]:
out = Pool(ignore_border)(input, ws).flatten()
yv = tensor.Rop(out, input, eval_p)
rop_f = function([], yv, on_unused_input='ignore')
sy, _ = theano.scan(lambda i, y, x, v:
(tensor.grad(y[i], x) * v).sum(),
sequences=tensor.arange(out.shape[0]),
non_sequences=[out, input, eval_p])
scan_f = function([], sy, on_unused_input='ignore')
v1 = rop_f()
v2 = scan_f()
assert numpy.allclose(v1, v2), ("Rop mismatch: %s %s" %
(v1, v2))
def test_conv(self):
for conv_op in [conv.conv2d, conv2d]:
for border_mode in ['valid', 'full']:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论