def check_forward(self, x_data, use_cudnn=True): dims = self.dims ksize = self.ksize stride = self.stride pad = self.pad x = chainer.Variable(x_data) y = functions.average_pooling_nd(x, ksize, stride, pad, use_cudnn=use_cudnn) self.assertEqual(y.data.dtype, self.dtype) y_data = cuda.to_cpu(y.data) self.assertEqual(self.gy.shape, y_data.shape) patches = pooling_nd_helper.pooling_patches(dims, ksize, stride, pad, False) for k in six.moves.range(2): for c in six.moves.range(3): x = self.x[k, c] size = functools.reduce(operator.mul, ksize) expect = numpy.array([x[idx].sum() for idx in patches]) expect = expect.reshape(y_data.shape[2:]) / size testing.assert_allclose(expect, y_data[k, c], **self.check_forward_options)
def check_forward(self, x_data, use_cudnn=True): dims = self.dims ksize = self.ksize stride = self.stride pad = self.pad x = chainer.Variable(x_data) y = functions.max_pooling_nd(x, ksize, stride=stride, pad=pad, cover_all=self.cover_all, use_cudnn=use_cudnn) self.assertEqual(y.data.dtype, self.dtype) y_data = cuda.to_cpu(y.data) self.assertEqual(self.gy.shape, y_data.shape) patches = pooling_nd_helper.pooling_patches( dims, ksize, stride, pad, self.cover_all) for k in six.moves.range(2): for c in six.moves.range(3): x = self.x[k, c] expect = numpy.array([x[idx].max() for idx in patches]) expect = expect.reshape(y_data.shape[2:]) testing.assert_allclose(expect, y_data[k, c])
def check_forward(self, x_data, use_cudnn='always'): dims = self.dims ksize = self.ksize stride = self.stride pad = self.pad x = chainer.Variable(x_data) with chainer.using_config('use_cudnn', use_cudnn): y = functions.average_pooling_nd(x, ksize, stride, pad) self.assertEqual(y.data.dtype, self.dtype) y_data = cuda.to_cpu(y.data) self.assertEqual(self.gy.shape, y_data.shape) patches = pooling_nd_helper.pooling_patches( dims, ksize, stride, pad, False) for k in six.moves.range(2): for c in six.moves.range(3): x = self.x[k, c] size = functools.reduce(operator.mul, ksize) expect = numpy.array([x[idx].sum() for idx in patches]) expect = expect.reshape(y_data.shape[2:]) / size testing.assert_allclose( expect, y_data[k, c], **self.check_forward_options)