Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

keras custom conv2d initialization

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.

like image 279
Jens R Avatar asked Feb 10 '26 20:02

Jens R


1 Answers

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.

like image 193
Autonomous Avatar answered Feb 12 '26 16:02

Autonomous



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!