Skip to content

Commit 6a4aab4

Browse files
committed
Fix border mode = same in Conv2D
1 parent 46e19b9 commit 6a4aab4

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

keras/layers/convolutional.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,14 @@ def get_output(self, train):
171171

172172
conv_out = theano.tensor.nnet.conv.conv2d(X, self.W,
173173
border_mode=border_mode, subsample=self.subsample)
174-
output = self.activation(conv_out + self.b.dimshuffle('x', 0, 'x', 'x'))
175174

176175
if self.border_mode == 'same':
177-
clip_row = (self.nb_row - 1) // 2
178-
clip_col = (self.nb_col - 1) // 2
179-
output = output[:, :, clip_row:-clip_row, clip_col:-clip_col]
180-
return output
176+
shift_x = (self.nb_row - 1) // 2
177+
shift_y = (self.nb_col - 1) // 2
178+
conv_out = conv_out[:, :, shift_x:X.shape[2] + shift_x, shift_y:X.shape[3] + shift_y]
179+
180+
return self.activation(conv_out + self.b.dimshuffle('x', 0, 'x', 'x'))
181+
181182

182183
def get_config(self):
183184
return {"name":self.__class__.__name__,

0 commit comments

Comments
 (0)