# How are weights organized in Conv2D layers?

I trained a model using Keras from this example. The model summary showed me this result

    Model: "sequential_1"
_________________________________________________________________
Layer (type)                 Output Shape              Param #
=================================================================
conv2d_1 (Conv2D)            (None, 26, 26, 32)        320
_________________________________________________________________
conv2d_2 (Conv2D)            (None, 24, 24, 64)        18496
_________________________________________________________________
max_pooling2d_1 (MaxPooling2 (None, 12, 12, 64)        0
_________________________________________________________________
dropout_1 (Dropout)          (None, 12, 12, 64)        0
_________________________________________________________________
flatten_1 (Flatten)          (None, 9216)              0
_________________________________________________________________
dense_1 (Dense)              (None, 128)               1179776
_________________________________________________________________
dropout_2 (Dropout)          (None, 128)               0
_________________________________________________________________
dense_2 (Dense)              (None, 10)                1290
=================================================================
Total params: 1,199,882
Trainable params: 1,199,882
Non-trainable params: 0


There are 8 layers and model.get_weights() also shows the first dimension of 8. As I understood correctly things like Pooling and Flatten are "operators" over the input matrices, so why it is presented as a layer? How to understand what is stored in weight array for example in Pooling layer (model.get_weights()[2])?

If you print those shapes using below for loop

weights_m=model.get_weights()
for i in range(8):
print(weights_m[i].shape)


you will get output as

(3, 3, 1, 32)
(32,)
(3, 3, 32, 64)
(64,)
(9216, 128)
(128,)
(128, 10)
(10,)

so we will get one layer weight and bias. we have a total of 4 layers(2 conv + 2 dense) so 8 weight vectors.

• subarrays with only one dimension are biases? Apr 12, 2020 at 18:57
• Yes. Those 1d arrays are biases. For every layer, you are using bias so 4 laters, 4 bias vectors.
– Uday
Apr 12, 2020 at 19:01
• ok thx it's clear Apr 12, 2020 at 19:03

3x3 weights + 1 bias for each feature map. It has 32 feature map.
This is first 2 lines. (3X3+1)X32. At this points feature size is 26X26(valid padding)


3x3 weights connected to 32 previous feature maps + 1 bias for each feature map. It has 64 feature maps.
This is 3rd and 4th lines (3X3X32+1)X64. At this points feature size is 24X24(valid padding)


At this points, feature size is 12X12(Pooling)


64 feature maps of size 12X12 are flattened. 144X64=9216 mapped to 128 neurons + 128 biases

128 neurons are mapped to 10 neurons + 10 biases