提交 8db25a7a authored 作者: Frederic's avatar Frederic

speed up pool when no pad

上级 91c1ca38
...@@ -234,11 +234,14 @@ class DownsampleFactorMax(Op): ...@@ -234,11 +234,14 @@ class DownsampleFactorMax(Op):
img_cols = x.shape[-1] + 2 * pad_w img_cols = x.shape[-1] + 2 * pad_w
# pad the image # pad the image
fill = x.min()-1. if self.padding != (0, 0):
y = numpy.zeros( fill = x.min()-1.
(x.shape[0], x.shape[1], img_rows, img_cols), y = numpy.zeros(
dtype=x.dtype) + fill (x.shape[0], x.shape[1], img_rows, img_cols),
y[:, :, pad_h:(img_rows-pad_h), pad_w:(img_cols-pad_w)] = x dtype=x.dtype) + fill
y[:, :, pad_h:(img_rows-pad_h), pad_w:(img_cols-pad_w)] = x
else:
y = x
# max pooling # max pooling
for n in xrange(x.shape[0]): for n in xrange(x.shape[0]):
for k in xrange(x.shape[1]): for k in xrange(x.shape[1]):
...@@ -386,10 +389,14 @@ class DownsampleFactorMaxGrad(Op): ...@@ -386,10 +389,14 @@ class DownsampleFactorMaxGrad(Op):
img_cols = x.shape[-1] + 2 * pad_w img_cols = x.shape[-1] + 2 * pad_w
# pad the image # pad the image
fill = x.min()-1 if self.padding != (0, 0):
y = numpy.zeros( fill = x.min()-1
(x.shape[0], x.shape[1], img_rows, img_cols), dtype=x.dtype) + fill y = numpy.zeros(
y[:, :, pad_h:(img_rows-pad_h), pad_w:(img_cols-pad_w)] = x (x.shape[0], x.shape[1], img_rows, img_cols),
dtype=x.dtype) + fill
y[:, :, pad_h:(img_rows-pad_h), pad_w:(img_cols-pad_w)] = x
else:
y = x
gx = numpy.zeros_like(y) gx = numpy.zeros_like(y)
for n in xrange(x.shape[0]): for n in xrange(x.shape[0]):
for k in xrange(x.shape[1]): for k in xrange(x.shape[1]):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论