提交 138f48ae authored 作者: Frédéric Bastien's avatar Frédéric Bastien 提交者: GitHub

Merge pull request #5090 from nouiz/fix_pool_shape_regression

Regression FIX
...@@ -170,9 +170,7 @@ class Pool(OpenMPOp): ...@@ -170,9 +170,7 @@ class Pool(OpenMPOp):
'average_exc_pad' include it) 'average_exc_pad' include it)
ndim : int ndim : int
The number of pooling dimensions N. The number of pooling dimensions N.
If this number is not specified, the default is set to the If this number is not specified, the default is set to 2.
(input.ndim - 2), assuming that the first two dimensions of the input
are non-pooling dimensions.
""" """
...@@ -206,9 +204,7 @@ class Pool(OpenMPOp): ...@@ -206,9 +204,7 @@ class Pool(OpenMPOp):
right margins. No padding is added if padding is None. right margins. No padding is added if padding is None.
ndim : int ndim : int
The number of pooling dimensions N. The number of pooling dimensions N.
If this number is not specified, the default is set to the If this number is not specified, the default is set to 2.
(input.ndim - 2), assuming that the first two dimensions of the input
are non-pooling dimensions.
Returns Returns
------- -------
...@@ -219,8 +215,8 @@ class Pool(OpenMPOp): ...@@ -219,8 +215,8 @@ class Pool(OpenMPOp):
""" """
if ndim is None: if ndim is None:
ndim = len(imgshape) - 2 ndim = 2
assert ndim > 0
if len(imgshape) < ndim: if len(imgshape) < ndim:
raise TypeError('imgshape must have at least {} dimensions'.format(ndim)) raise TypeError('imgshape must have at least {} dimensions'.format(ndim))
...@@ -259,6 +255,8 @@ class Pool(OpenMPOp): ...@@ -259,6 +255,8 @@ class Pool(OpenMPOp):
def __init__(self, ignore_border=False, mode='max', ndim=None, openmp=None): def __init__(self, ignore_border=False, mode='max', ndim=None, openmp=None):
super(Pool, self).__init__(openmp=openmp) super(Pool, self).__init__(openmp=openmp)
if ndim is None:
ndim = 2
self.ndim = ndim self.ndim = ndim
self.ignore_border = ignore_border self.ignore_border = ignore_border
if mode not in ['max', 'average_inc_pad', 'average_exc_pad', 'sum']: if mode not in ['max', 'average_inc_pad', 'average_exc_pad', 'sum']:
...@@ -301,8 +299,6 @@ class Pool(OpenMPOp): ...@@ -301,8 +299,6 @@ class Pool(OpenMPOp):
# TODO: consider restricting the dtype? # TODO: consider restricting the dtype?
x = tensor.as_tensor_variable(x) x = tensor.as_tensor_variable(x)
nd = self.ndim nd = self.ndim
if nd is None:
nd = x.type.ndim - 2
if stride is None: if stride is None:
stride = ws stride = ws
if pad is None: if pad is None:
......
...@@ -25,6 +25,10 @@ from theano import function ...@@ -25,6 +25,10 @@ from theano import function
class TestDownsampleFactorMax(utt.InferShapeTester): class TestDownsampleFactorMax(utt.InferShapeTester):
def test_out_shape(self):
assert Pool.out_shape((9, 8, 6), (2, 2)) == [9, 4, 3]
assert Pool.out_shape((8, 6), (2, 2)) == [4, 3]
@staticmethod @staticmethod
def numpy_max_pool_2d(input, ds, ignore_border=False, mode='max'): def numpy_max_pool_2d(input, ds, ignore_border=False, mode='max'):
'''Helper function, implementing pool_2d in pure numpy''' '''Helper function, implementing pool_2d in pure numpy'''
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论