def check_forward(self, x_data, use_cudnn=True):
x = chainer.Variable(x_data)
y = functions.max_pooling_2d(x, 3, stride=2, pad=1,
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)
for k in six.moves.range(2):
for c in six.moves.range(3):
x = self.x[k, c]
if self.cover_all:
expect = numpy.array([
[x[0:2, 0:2].max(), x[0:2, 1:3].max()],
[x[1:4, 0:2].max(), x[1:4, 1:3].max()],
[x[3:4, 0:2].max(), x[3:4, 1:3].max()]])
else:
expect = numpy.array([
[x[0:2, 0:2].max(), x[0:2, 1:3].max()],
[x[1:4, 0:2].max(), x[1:4, 1:3].max()]])
gradient_check.assert_allclose(expect, y_data[k, c])
评论列表
文章目录