Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assert output size of max_pooling_2d in GPU cases #2589

Merged
merged 4 commits into from Apr 19, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions chainer/functions/pooling/max_pooling_2d.py
Expand Up @@ -34,8 +34,10 @@ def forward_gpu(self, x):
n, c, h, w = x[0].shape
y_h = conv.get_conv_outsize(
h, self.kh, self.sy, self.ph, self.cover_all)
assert y_h > 0, 'Height in the output should be positive.'
y_w = conv.get_conv_outsize(
w, self.kw, self.sx, self.pw, self.cover_all)
assert y_w > 0, 'Width in the output should be positive.'
y = cuda.cupy.empty((n, c, y_h, y_w), dtype=x[0].dtype)
self.indexes = cuda.cupy.empty((n, c, y_h, y_w), dtype=numpy.int32)

Expand Down
2 changes: 2 additions & 0 deletions chainer/functions/pooling/pooling_2d.py
Expand Up @@ -53,8 +53,10 @@ def forward_gpu(self, x):
n, c, h, w = x.shape
y_h = conv.get_conv_outsize(
h, self.kh, self.sy, self.ph, self.cover_all)
assert y_h > 0, 'Height in the output should be positive.'
y_w = conv.get_conv_outsize(
w, self.kw, self.sx, self.pw, self.cover_all)
assert y_w > 0, 'Width in the output should be positive.'
y = cuda.cupy.empty((n, c, y_h, y_w), dtype=x.dtype)

handle = cudnn.get_handle()
Expand Down
Expand Up @@ -65,6 +65,18 @@ def test_forward_cpu_wide(self): # see #120
x = chainer.Variable(x_data)
functions.max_pooling_2d(x, 6, stride=6, pad=0)

def test_forward_output_size_zero_cpu(self):
with self.assertRaisesRegexp(
AssertionError, 'Height in the output should be positive.'):
x_data = numpy.random.rand(4, 4, 1, 4).astype(self.dtype)
x = chainer.Variable(x_data)
functions.max_pooling_2d(x, 3, stride=2)
with self.assertRaisesRegexp(
AssertionError, 'Width in the output should be positive.'):
x_data = numpy.random.rand(4, 4, 4, 1).astype(self.dtype)
x = chainer.Variable(x_data)
functions.max_pooling_2d(x, 3, stride=2)

@attr.gpu
@condition.retry(3)
def test_forward_gpu(self):
Expand All @@ -75,6 +87,34 @@ def test_forward_gpu(self):
def test_forward_gpu_no_cudnn(self):
self.check_forward(cuda.to_gpu(self.x), False)

@attr.gpu
@condition.retry(3)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This statement is redundant.
Please remove this.

def test_forward_output_size_zero_gpu(self):
with self.assertRaisesRegexp(
AssertionError, 'Height in the output should be positive.'):
x_data = cuda.cupy.random.rand(4, 4, 1, 4).astype(self.dtype)
x = chainer.Variable(x_data)
functions.max_pooling_2d(x, 3, stride=2, use_cudnn=False)
with self.assertRaisesRegexp(
AssertionError, 'Width in the output should be positive.'):
x_data = cuda.cupy.random.rand(4, 4, 4, 1).astype(self.dtype)
x = chainer.Variable(x_data)
functions.max_pooling_2d(x, 3, stride=2, use_cudnn=False)

@attr.cudnn
@condition.retry(3)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This statement is redundant.
Please remove this.

def test_forward_output_size_zero_cudnn(self):
with self.assertRaisesRegexp(
AssertionError, 'Height in the output should be positive.'):
x_data = cuda.cupy.random.rand(4, 4, 1, 4).astype(self.dtype)
x = chainer.Variable(x_data)
functions.max_pooling_2d(x, 3, stride=2, use_cudnn=True)
with self.assertRaisesRegexp(
AssertionError, 'Width in the output should be positive.'):
x_data = cuda.cupy.random.rand(4, 4, 4, 1).astype(self.dtype)
x = chainer.Variable(x_data)
functions.max_pooling_2d(x, 3, stride=2, use_cudnn=True)

def check_backward(self, x_data, y_grad, use_cudnn=True):
gradient_check.check_backward(
functions.MaxPooling2D(
Expand Down