From fa682535dcc80eed8a5ff1db9553c2e285d424bb Mon Sep 17 00:00:00 2001 From: Thomas McColgan Date: Fri, 12 Jun 2015 14:00:50 +0200 Subject: [PATCH 1/2] Straightforward copying of regularization and constraints --- keras/layers/convolutional.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/keras/layers/convolutional.py b/keras/layers/convolutional.py index a250ed461b1..d3be5f8aa1e 100644 --- a/keras/layers/convolutional.py +++ b/keras/layers/convolutional.py @@ -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 @@ -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) From c9dbbe4c2cc4d0eef09322b442c0ff55962c8fe2 Mon Sep 17 00:00:00 2001 From: Thomas McColgan Date: Fri, 12 Jun 2015 15:19:02 +0200 Subject: [PATCH 2/2] add constraints and regularisation to conv2d --- keras/layers/convolutional.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/keras/layers/convolutional.py b/keras/layers/convolutional.py index d3be5f8aa1e..6d4db99ec74 100644 --- a/keras/layers/convolutional.py +++ b/keras/layers/convolutional.py @@ -86,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) @@ -106,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)