My first layer is:
model.add(tf.keras.layers.Conv2D(filters=32, kernel_size=3, padding="same", activation="relu", input_shape=[32, 32, 3]))
And the number of parameters in the Model summary table:
Layer (type) Output Shape Param #
=================================================================
conv2d_4 (Conv2D) (None, 32, 32, 32) 896
As per my understanding, the number of parameters must be :
(No of filters) X (Number of parameters in Kernel)
i.e. in my case ==> 32 X (3 X 3) = 288
But its 896. How it comes to 896?
Thanks
In a CNN, each layer has two kinds of parameters : weights and biases. The total number of parameters is just the sum of all weights and biases. = Number of weights of the Conv Layer. = Number of biases of the Conv Layer.
Convolutional_1 : ((kernel_size)*stride+1)*filters) = 3*3*1+1*32 = 320 parameters. In first layer, the convolutional layer has 32 filters.
Just keep in mind that in order to find the total number of parameters we need to sum up the following: product of the number of neurons in the input layer and first hidden layer. sum of products of the number of neurons between the two consecutive hidden layers.
You may need to tune the exact value depending on (1) the complexity of your dataset and (2) the depth of your neural network, but I recommend starting with filters in the range [32, 64, 128] in the earlier and increasing up to [256, 512, 1024] in the deeper layers.
Number of parameters in Keras Conv2D layer is calculated using the following equation:
number_parameters = out_channels * (in_channels * kernel_h * kernel_w + 1) # 1 for bias
So, in your case,
in_channels = 3
out_channels = 32
kernel_h = kernel_w = 3
number_parameters = 32(3*3*3 + 1) = 896
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With