Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding number of parameters in Keras Conv2D layer

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

like image 773
Lakshay Avatar asked Nov 22 '19 09:11

Lakshay


People also ask

How does CNN determine number of parameters?

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.

How many parameters are in a convolutional layer?

Convolutional_1 : ((kernel_size)*stride+1)*filters) = 3*3*1+1*32 = 320 parameters. In first layer, the convolutional layer has 32 filters.

How do you determine the number of parameters in a neural network model?

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.

How do you determine the number of filters in a Conv2D?

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.


1 Answers

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
like image 159
Kaushik Roy Avatar answered Oct 16 '22 02:10

Kaushik Roy