1
votes

The syntax for adding Convolution2D layer is Keras is https://keras.io/layers/convolutional/#convolution2d. I am unable to pass "weights" argument correctly. How should I do that?

2

2 Answers

1
votes
conv1_1 = Conv2D(64, kernel_size=(3, 3), activation='relu', padding='same',
                            weight_and_bias=[weight, biases], name='conv1_1')(input)

The shape of weight is (nb_filter, nb_channel, filter_size, filter_size), shape of biases is (nb_channel,)

0
votes

You should pass a list of numpy arrays to set as initial weights.

For Convolution2D, weights list have two items, one in shape (nb_filter, nb_channel, nb_row, nb_col) and bias in shape (nb_filter,).

According to the author of Keras:

If you have doubts about what these shapes are, you can simply instantiate your layer then call get_weights(), and look at the output. The argument weights, and also the method set_weights(weights), expect exactly the same format as the output of get_weights().