From 7610c55bdc046ff0b0d6300af5ea9dcfd0a427cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Branchaud-Charron?= Date: Mon, 16 Oct 2017 18:09:35 -0400 Subject: [PATCH] Add dilation to SeparableConv2D (#8152) * Add dilation to SeparableConv2D * pep8 --- keras/layers/convolutional.py | 22 ++-------------------- tests/keras/layers/convolutional_test.py | 24 ++++++++++++++---------- 2 files changed, 16 insertions(+), 30 deletions(-) diff --git a/keras/layers/convolutional.py b/keras/layers/convolutional.py index 70f0a4dc911..6719eac9848 100644 --- a/keras/layers/convolutional.py +++ b/keras/layers/convolutional.py @@ -1217,7 +1217,8 @@ def call(self, inputs): self.pointwise_kernel, data_format=self.data_format, strides=self.strides, - padding=self.padding) + padding=self.padding, + dilation_rate=self.dilation_rate) if self.bias: outputs = K.bias_add( @@ -1229,25 +1230,6 @@ def call(self, inputs): return self.activation(outputs) return outputs - def compute_output_shape(self, input_shape): - if self.data_format == 'channels_first': - rows = input_shape[2] - cols = input_shape[3] - elif self.data_format == 'channels_last': - rows = input_shape[1] - cols = input_shape[2] - - rows = conv_utils.conv_output_length(rows, self.kernel_size[0], - self.padding, - self.strides[0]) - cols = conv_utils.conv_output_length(cols, self.kernel_size[1], - self.padding, - self.strides[1]) - if self.data_format == 'channels_first': - return (input_shape[0], self.filters, rows, cols) - elif self.data_format == 'channels_last': - return (input_shape[0], rows, cols, self.filters) - def get_config(self): config = super(SeparableConv2D, self).get_config() config.pop('kernel_initializer') diff --git a/tests/keras/layers/convolutional_test.py b/tests/keras/layers/convolutional_test.py index dc4868b30af..66e48f306a4 100644 --- a/tests/keras/layers/convolutional_test.py +++ b/tests/keras/layers/convolutional_test.py @@ -241,16 +241,20 @@ def test_separable_conv_2d(): for padding in _convolution_paddings: for strides in [(1, 1), (2, 2)]: for multiplier in [1, 2]: - if padding == 'same' and strides != (1, 1): - continue - - layer_test(convolutional.SeparableConv2D, - kwargs={'filters': filters, - 'kernel_size': (3, 3), - 'padding': padding, - 'strides': strides, - 'depth_multiplier': multiplier}, - input_shape=(num_samples, num_row, num_col, stack_size)) + for dilation_rate in [(1, 1), (2, 2), (2, 1), (1, 2)]: + if padding == 'same' and strides != (1, 1): + continue + if dilation_rate != (1, 1) and strides != (1, 1): + continue + + layer_test(convolutional.SeparableConv2D, + kwargs={'filters': filters, + 'kernel_size': (3, 3), + 'padding': padding, + 'strides': strides, + 'depth_multiplier': multiplier, + 'dilation_rate': dilation_rate}, + input_shape=(num_samples, num_row, num_col, stack_size)) layer_test(convolutional.SeparableConv2D, kwargs={'filters': filters,