提交 734db136 authored 作者: Frederic Bastien's avatar Frederic Bastien

Fix gh-4534. If ds size for pool is equal to image size and ignore_border=False,…

Fix gh-4534. If ds size for pool is equal to image size and ignore_border=False, use the correct shape.
上级 5af163f7
...@@ -278,6 +278,9 @@ class Pool(Op): ...@@ -278,6 +278,9 @@ class Pool(Op):
'Pool requires 4D input for now') 'Pool requires 4D input for now')
z_shape = self.out_shape(x.shape, self.ds, self.ignore_border, self.st, z_shape = self.out_shape(x.shape, self.ds, self.ignore_border, self.st,
self.padding) self.padding)
if not self.ignore_border:
assert z_shape[2] > 0
assert z_shape[3] > 0
if (z[0] is None) or (z[0].shape != z_shape): if (z[0] is None) or (z[0].shape != z_shape):
z[0] = numpy.empty(z_shape, dtype=x.dtype) z[0] = numpy.empty(z_shape, dtype=x.dtype)
zz = z[0] zz = z[0]
...@@ -407,7 +410,7 @@ class Pool(Op): ...@@ -407,7 +410,7 @@ class Pool(Op):
} }
else else
{ {
z_r = std::max(0, (r - 1 - %(ds0)s) / %(st0)s + 1) + 1; z_r = std::max(0, (r - 1 - %(ds0)s + %(st0)s) / %(st0)s) + 1;
} }
// decide how many columns the output has // decide how many columns the output has
if (%(st1)s >= %(ds1)s) if (%(st1)s >= %(ds1)s)
...@@ -416,8 +419,10 @@ class Pool(Op): ...@@ -416,8 +419,10 @@ class Pool(Op):
} }
else else
{ {
z_c = std::max(0, (c - 1 - %(ds1)s) / %(st1)s + 1) + 1; z_c = std::max(0, (c - 1 - %(ds1)s + %(st0)s) / %(st1)s) + 1;
} }
assert(z_r > 0);
assert(z_c > 0);
} }
// memory allocation of z if necessary // memory allocation of z if necessary
if ((!%(z)s) if ((!%(z)s)
...@@ -526,7 +531,7 @@ class Pool(Op): ...@@ -526,7 +531,7 @@ class Pool(Op):
return ccode % locals() return ccode % locals()
def c_code_cache_version(self): def c_code_cache_version(self):
return (0, 6, 8, 3) return (0, 6, 8, 4)
class PoolGrad(Op): class PoolGrad(Op):
......
...@@ -208,17 +208,21 @@ class TestDownsampleFactorMax(utt.InferShapeTester): ...@@ -208,17 +208,21 @@ class TestDownsampleFactorMax(utt.InferShapeTester):
def test_DownsampleFactorMaxStride(self): def test_DownsampleFactorMaxStride(self):
rng = numpy.random.RandomState(utt.fetch_seed()) rng = numpy.random.RandomState(utt.fetch_seed())
maxpoolshps = ((1, 1), (3, 3), (5, 3)) maxpoolshps = ((1, 1), (3, 3), (5, 3), (16, 16))
stridesizes = ((1, 1), (3, 3), (5, 7)) stridesizes = ((1, 1), (3, 3), (5, 7),)
# generate random images # generate random images
imval = rng.rand(4, 10, 16, 16) imval = rng.rand(4, 10, 16, 16)
# The same for each mode # The same for each mode
outputshps = ((4, 10, 16, 16), (4, 10, 6, 6), (4, 10, 4, 3), outputshps = (
(4, 10, 16, 16), (4, 10, 6, 6), (4, 10, 4, 3),
(4, 10, 16, 16), (4, 10, 6, 6), (4, 10, 4, 3), (4, 10, 16, 16), (4, 10, 6, 6), (4, 10, 4, 3),
(4, 10, 14, 14), (4, 10, 5, 5), (4, 10, 3, 2), (4, 10, 14, 14), (4, 10, 5, 5), (4, 10, 3, 2),
(4, 10, 14, 14), (4, 10, 6, 6), (4, 10, 4, 3), (4, 10, 14, 14), (4, 10, 6, 6), (4, 10, 4, 3),
(4, 10, 12, 14), (4, 10, 4, 5), (4, 10, 3, 2), (4, 10, 12, 14), (4, 10, 4, 5), (4, 10, 3, 2),
(4, 10, 12, 14), (4, 10, 5, 6), (4, 10, 4, 3)) (4, 10, 12, 14), (4, 10, 5, 6), (4, 10, 4, 3),
(4, 10, 1, 1), (4, 10, 1, 1), (4, 10, 1, 1),
(4, 10, 1, 1), (4, 10, 1, 1), (4, 10, 1, 1),)
images = tensor.dtensor4() images = tensor.dtensor4()
indx = 0 indx = 0
for mode, maxpoolshp, ignore_border in product(['max', for mode, maxpoolshp, ignore_border in product(['max',
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论