Conv2D general question

I have a very basic question, but I couldn’t get the idea about 2D convolution in Keras. When we are creating a model during C4W1A2 :

model = tf.keras.Sequential(
[tf.keras.layers.ZeroPadding2D(padding=(3,3), input_shape=(64,64,3)),
tf.keras.layers.Conv2D(filters=1, kernel_size=(7,7))])

why the output shape is (None, 64, 64, 1) :


Layer (type) Output Shape Param #


zero_padding2d_70 (ZeroPaddi (None, 70, 70, 3) 0


conv2d_72 (Conv2D) (None, 64, 64, 1) 148


Total params: 148
Trainable params: 148
Non-trainable params: 0


and not (None, 64, 64, 3) with 148 parameters?
As far as I understand, the 2D convolution is not a volume convolution, the window is a 2D-matrix, but not a 3D-cube, so could somebody please explain why do we have 64, 64, 1 instead of 64, 64, 3?

When they say 2D convolution, they just mean you have height and width in addition to the channels. The inputs here are 64 x 64 x 3. So each filter will have shape 7 x 7 x 3 and it is a “convolution over volume”. But because there is only one such filter, we get only 1 output channel.

The number of trainable parameters is 7 * 7 * 3 + 1. That last 1 is for the bias term on the one filter. That equals 148, right?

1 Like

Exactly, 148 ! Thank you so much for your explanation! And especially for +1 term, because it was not very clear where 148 comes from.