提交 1ad6fae7 authored 作者: Cesar Laurent's avatar Cesar Laurent

Adapted the new DownsampleFactorMaxGradGrad gradient.

上级 96a96b6f
...@@ -1089,13 +1089,18 @@ class DownsampleFactorMaxGradGrad(OpenMPOp): ...@@ -1089,13 +1089,18 @@ class DownsampleFactorMaxGradGrad(OpenMPOp):
return [in_shapes[1]] return [in_shapes[1]]
def grad(self, inp, grads): def grad(self, inp, grads):
x, maxout, ggx = inp x, maxout, ggx, ws, stride, pad = inp
gz, = grads gz, = grads
return [theano.tensor.zeros_like(x), return [theano.tensor.zeros_like(x),
theano.tensor.zeros_like(maxout), theano.tensor.zeros_like(maxout),
MaxPoolGrad( MaxPoolGrad(ignore_border=self.ignore_border)(x, maxout, gz,
self.ds, ignore_border=self.ignore_border, ws, stride, pad),
st=self.st, padding=self.padding)(x, maxout, gz)] DisconnectedType()(),
DisconnectedType()(),
DisconnectedType()()]
def connection_pattern(self, node):
return [[1], [1], [1], [0], [0], [0]]
def c_code(self, node, name, inp, out, sub): def c_code(self, node, name, inp, out, sub):
if self.mode != 'max': if self.mode != 'max':
......
...@@ -644,16 +644,12 @@ class TestDownsampleFactorMax(utt.InferShapeTester): ...@@ -644,16 +644,12 @@ class TestDownsampleFactorMax(utt.InferShapeTester):
paddingsize = paddingsizes[i] paddingsize = paddingsizes[i]
def mp(input1, input2): def mp(input1, input2):
pooled_out = Pool( op1 = Pool(ignore_border=True)
maxpoolsize, ignore_border=True, pooled_out = op1(input1, maxpoolsize, stride=stridesize,
st=stridesize, pad=paddingsize)
padding=paddingsize, op2 = DownsampleFactorMaxGradGrad(ignore_border=True)
)(input1) out = op2(input1, pooled_out, input2, ws=maxpoolsize,
out = DownsampleFactorMaxGradGrad( stride=stridesize, pad=paddingsize)
ds=maxpoolsize,
ignore_border=True,
st=stridesize,
padding=paddingsize)(input1, pooled_out, input2)
return out return out
utt.verify_grad(mp, [imval1, imval2], rng=rng) utt.verify_grad(mp, [imval1, imval2], rng=rng)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论