提交 b14a0e30 authored 作者: Li's avatar Li

better wording

上级 bd5dc5a8
......@@ -39,6 +39,10 @@ def max_pool_2d(input, ds, ignore_border=False, st=None, padding=(0, 0)):
over rows/cols to get the the next pool region.
if st is None, it is considered equal to ds
(no overlap on pooling regions)
:param padding: (pad_h, pad_w), pad zeros to extend beyond four borders
of the images, pad_h is the size of the top and bottom margins,
and pad_w is the size of the left and right margins.
:type padding: tuple of two ints
"""
if input.ndim < 2:
......@@ -101,8 +105,9 @@ class DownsampleFactorMax(Op):
extra row/col of partial downsampling (False) or ignore it (True).
:type ignore_border: bool
:param padding: (pad_h, pad_w), pad zeros on four borders
of the images, pad_h for padding rows, and pad_w for columns.
:param padding: (pad_h, pad_w), pad zeros to extend beyond four borders
of the images, pad_h is the size of the top and bottom margins,
and pad_w is the size of the left and right margins.
:type padding: tuple of two ints
:rtype: list
......@@ -172,8 +177,9 @@ class DownsampleFactorMax(Op):
(no overlap on pooling regions)
: type st: list or tuple of two ints
:param padding: (pad_h, pad_w), pad zeros on four borders
of the images, pad_h for padding rows, and pad_w for columns.
:param padding: (pad_h, pad_w), pad zeros to extend beyond four borders
of the images, pad_h is the size of the top and bottom margins,
and pad_w is the size of the left and right margins.
:type padding: tuple of two ints
"""
......@@ -226,10 +232,11 @@ class DownsampleFactorMax(Op):
pc = zz.shape[-1]
ds0, ds1 = self.ds
st0, st1 = self.st
img_rows = x.shape[-2] + 2 * self.padding[0]
img_cols = x.shape[-1] + 2 * self.padding[1]
pad_h = self.padding[0]
pad_w = self.padding[1]
img_rows = x.shape[-2] + 2 * pad_h
img_cols = x.shape[-1] + 2 * pad_w
# pad the image
fill = x.min()-1.
......@@ -377,10 +384,11 @@ class DownsampleFactorMaxGrad(Op):
pc = maxout.shape[-1]
ds0, ds1 = self.ds
st0, st1 = self.st
img_rows = x.shape[-2] + 2 * self.padding[0]
img_cols = x.shape[-1] + 2 * self.padding[1]
pad_h = self.padding[0]
pad_w = self.padding[1]
img_rows = x.shape[-2] + 2 * pad_h
img_cols = x.shape[-1] + 2 * pad_w
# pad the image
fill = x.min()-1
y = numpy.zeros(
......
......@@ -267,18 +267,24 @@ class TestDownsampleFactorMax(utt.InferShapeTester):
def test_DownsampleFactorMaxPaddingStride_grad(self):
rng = numpy.random.RandomState(utt.fetch_seed())
imval = rng.rand(1, 1, 10, 10) * 10.0
maxpoolsize = (5, 3)
stridesize = (3, 2)
paddingsize = (2, 2)
def mp(input):
return DownsampleFactorMax(
maxpoolsize, ignore_border=True,
st=stridesize,
padding=paddingsize,
)(input)
utt.verify_grad(mp, [imval], rng=rng)
imgsizes = ((10, 10), (10, 5))
maxpoolsizes = ((5, 3),(3, 5))
stridesizes = ((3, 2), (2, 3))
paddingsizes = ((2, 2),(2, 1))
for i in range(len(imgsizes)):
imgsize = imgsizes[i]
imval = rng.rand(1, 1, imgsize[0], imgsize[1]) * 10.0
maxpoolsize = maxpoolsizes[i]
stridesize = stridesizes[i]
paddingsize = paddingsizes[i]
def mp(input):
return DownsampleFactorMax(
maxpoolsize, ignore_border=True,
st=stridesize,
padding=paddingsize,
)(input)
utt.verify_grad(mp, [imval], rng=rng)
def test_DownsampleFactorMax_grad(self):
rng = numpy.random.RandomState(utt.fetch_seed())
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论