Skip to content

Commit

Permalink
Add dilation to SeparableConv2D (#8152)
Browse files Browse the repository at this point in the history
* Add dilation to SeparableConv2D

* pep8
  • Loading branch information
Frédéric Branchaud-Charron authored and fchollet committed Oct 16, 2017
1 parent 12ea236 commit 7610c55
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 30 deletions.
22 changes: 2 additions & 20 deletions keras/layers/convolutional.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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')
Expand Down
24 changes: 14 additions & 10 deletions tests/keras/layers/convolutional_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 7610c55

Please sign in to comment.