From 5a4138b66b588d05d5d9c7a518fcf407f8cbf693 Mon Sep 17 00:00:00 2001 From: hedaoyuan Date: Mon, 18 Sep 2017 13:47:34 +0800 Subject: [PATCH] Add test with groups=1. --- .../v2/framework/tests/test_conv2d_op.py | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/python/paddle/v2/framework/tests/test_conv2d_op.py b/python/paddle/v2/framework/tests/test_conv2d_op.py index 660eb31962f..64aeb6e8a91 100644 --- a/python/paddle/v2/framework/tests/test_conv2d_op.py +++ b/python/paddle/v2/framework/tests/test_conv2d_op.py @@ -5,6 +5,7 @@ from op_test import OpTest class TestConv2dOp(OpTest): def setUp(self): + self.init_groups() self.op_type = "conv2d" batch_size = 2 input_channels = 3 @@ -15,7 +16,6 @@ class TestConv2dOp(OpTest): filter_width = 3 stride = 1 padding = 0 - groups = 3 output_height = (input_height - filter_height + 2 * padding ) / stride + 1 output_width = (input_width - filter_width + 2 * padding) / stride + 1 @@ -23,18 +23,22 @@ class TestConv2dOp(OpTest): input_width)).astype("float32") filter = np.random.random( - (output_channels, input_channels / groups, filter_height, + (output_channels, input_channels / self.groups, filter_height, filter_width)).astype("float32") output = np.ndarray( (batch_size, output_channels, output_height, output_width)) self.inputs = {'Input': input, 'Filter': filter} - self.attrs = {'strides': [1, 1], 'paddings': [0, 0], 'groups': groups} + self.attrs = { + 'strides': [1, 1], + 'paddings': [0, 0], + 'groups': self.groups + } - output_group_channels = output_channels / groups - input_group_channels = input_channels / groups + output_group_channels = output_channels / self.groups + input_group_channels = input_channels / self.groups for batchid in xrange(batch_size): - for group in xrange(groups): + for group in xrange(self.groups): for outchannelid in range(group * output_group_channels, (group + 1) * output_group_channels): for rowid in xrange(output_height): @@ -71,6 +75,14 @@ class TestConv2dOp(OpTest): def test_check_grad(self): self.check_grad(set(['Input', 'Filter']), 'Output') + def init_groups(self): + self.groups = 1 + + +class TestWithGroup(TestConv2dOp): + def init_groups(self): + self.groups = 3 + if __name__ == '__main__': unittest.main() -- GitLab