提交 5a4138b6 编写于 作者: H hedaoyuan

Add test with groups=1.

上级 91afa0d8
...@@ -5,6 +5,7 @@ from op_test import OpTest ...@@ -5,6 +5,7 @@ from op_test import OpTest
class TestConv2dOp(OpTest): class TestConv2dOp(OpTest):
def setUp(self): def setUp(self):
self.init_groups()
self.op_type = "conv2d" self.op_type = "conv2d"
batch_size = 2 batch_size = 2
input_channels = 3 input_channels = 3
...@@ -15,7 +16,6 @@ class TestConv2dOp(OpTest): ...@@ -15,7 +16,6 @@ class TestConv2dOp(OpTest):
filter_width = 3 filter_width = 3
stride = 1 stride = 1
padding = 0 padding = 0
groups = 3
output_height = (input_height - filter_height + 2 * padding output_height = (input_height - filter_height + 2 * padding
) / stride + 1 ) / stride + 1
output_width = (input_width - filter_width + 2 * padding) / stride + 1 output_width = (input_width - filter_width + 2 * padding) / stride + 1
...@@ -23,18 +23,22 @@ class TestConv2dOp(OpTest): ...@@ -23,18 +23,22 @@ class TestConv2dOp(OpTest):
input_width)).astype("float32") input_width)).astype("float32")
filter = np.random.random( filter = np.random.random(
(output_channels, input_channels / groups, filter_height, (output_channels, input_channels / self.groups, filter_height,
filter_width)).astype("float32") filter_width)).astype("float32")
output = np.ndarray( output = np.ndarray(
(batch_size, output_channels, output_height, output_width)) (batch_size, output_channels, output_height, output_width))
self.inputs = {'Input': input, 'Filter': filter} 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 output_group_channels = output_channels / self.groups
input_group_channels = input_channels / groups input_group_channels = input_channels / self.groups
for batchid in xrange(batch_size): 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, for outchannelid in range(group * output_group_channels,
(group + 1) * output_group_channels): (group + 1) * output_group_channels):
for rowid in xrange(output_height): for rowid in xrange(output_height):
...@@ -71,6 +75,14 @@ class TestConv2dOp(OpTest): ...@@ -71,6 +75,14 @@ class TestConv2dOp(OpTest):
def test_check_grad(self): def test_check_grad(self):
self.check_grad(set(['Input', 'Filter']), 'Output') 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__': if __name__ == '__main__':
unittest.main() unittest.main()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册