Skip to content

Commit

Permalink
Merge pull request keras-team#218 from phreeza/conv_reg
Browse files Browse the repository at this point in the history
Add regularization and constraints for Convolution1D and Convolution2D
  • Loading branch information
fchollet committed Jun 12, 2015
2 parents 46d3bd5 + c9dbbe4 commit 161d47b
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions keras/layers/convolutional.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
class Convolution1D(Layer):
def __init__(self, nb_filter, stack_size, filter_length,
init='uniform', activation='linear', weights=None,
image_shape=None, border_mode='valid', subsample_length=1):
image_shape=None, border_mode='valid', subsample_length=1,
W_regularizer=None, b_regularizer=None, W_constraint=None, b_constraint=None):

nb_row = 1
nb_col = filter_length
Expand All @@ -35,6 +36,9 @@ def __init__(self, nb_filter, stack_size, filter_length,

self.params = [self.W, self.b]

self.regularizers = [W_regularizer, b_regularizer]
self.constraints = [W_constraint, b_constraint]

if weights is not None:
self.set_weights(weights)

Expand Down Expand Up @@ -82,7 +86,8 @@ def get_config(self):
class Convolution2D(Layer):
def __init__(self, nb_filter, stack_size, nb_row, nb_col,
init='glorot_uniform', activation='linear', weights=None,
image_shape=None, border_mode='valid', subsample=(1,1)):
image_shape=None, border_mode='valid', subsample=(1,1),
W_regularizer=None, b_regularizer=None, W_constraint=None, b_constraint=None):
super(Convolution2D,self).__init__()

self.init = initializations.get(init)
Expand All @@ -102,6 +107,9 @@ def __init__(self, nb_filter, stack_size, nb_row, nb_col,

self.params = [self.W, self.b]

self.regularizers = [W_regularizer, b_regularizer]
self.constraints = [W_constraint, b_constraint]

if weights is not None:
self.set_weights(weights)

Expand Down

0 comments on commit 161d47b

Please sign in to comment.