My model:
classifier = Sequential()
# Convolutional + MaxPooling -> 1
classifier.add(Conv2D(32, (3,3), input_shape = (IMAGE_SIZE, IMAGE_SIZE, 3)))
convout1 = Activation('relu')
classifier.add(convout1)
classifier.add(MaxPooling2D(pool_size = (2,2)))
classifier.add(Dropout(0.25))
I am running the following code to get weights
classifier.layers[0].get_weights()[0]
It returns an array of 3x3x3x32
. Shouldn't it return 32 matrices of 3x3
?
The weights shape is correct, because the convolutional filter is applied to the whole 3D input volume and the parameters for different channels are not shared (though they are shared spatially). See the picture from CS231n class:
Yes, the output volume is obtained by summing up the convolutions across the depth volume, but the parameters in each channel are different.
In your case, the channels are RGB (since input_shape = (IMAGE_SIZE, IMAGE_SIZE, 3)
), the spatial filter size is 3x3
and there are 32
filters. Hence the result shape is 3x3x3x32
and shape of each filter is 3x3x3
.