3
votes

I been trying to figure out how to create a custom initialization for Conv2D layers in Keras. Could any one show an example on how to manually create a "filter" or weights model as the starting point for training. i.e I would like to pass in a 2d matrix with weights, that can be used as a starting point, to the Conv2D layer. The matrix could be a gaussian blur filter or a sharpinging filter or edge detector etc.

JR

1

1 Answers

2
votes

From Keras documentation on custom initializers:

from keras import backend as K

def my_init(shape, dtype=None):
    return K.random_normal(shape, dtype=dtype)    

model.add(Dense(64, init=my_init))

So you can easily define an appropriate, custom initialization in my_init() and use that in your Conv2D layers.