Steps of Calculate the number of Parameter in CNN
To calculate the total number of parameters in a 2D convolutional neural network, sum the parameters from all layers, including convolutional, fully connected, and batch normalization layers, while excluding pooling layers as they contribute zero parameters.
1. Convolutional Layer
For a convolutional layer, the number of parameters is determined by the size of the filters (kernels), the number of filters, and the number of input channels.
We can calculate the parameter in the following manner:
Parameters=[Tex](k_w \times k_h \times C_{in} +1)\times C_{out}[/Tex]
Where:
- [Tex]k_w[/Tex] = kernel width
- [Tex]k_h[/Tex] = kernel height
- [Tex]C_{in}[/Tex] = number of input channels
- [Tex]C_{out}[/Tex]= number of filters (output channels)
The “+ 1” accounts for the bias term for each filter.
Let’s consider an example, where the convolutional layer with 32 filters of size 3×3 is given, and has an input with 3 channels:
[Tex] Parameters=(3Ă—3Ă—3+1)Ă—32 =(27+1)Ă—32=28Ă—32 =896[/Tex]
2. Fully Connected (Dense) Layers
For a fully connected layer, the number of parameters is given by the number of input units times the number of output units, plus one bias term for each output unit.
[Tex]Parameters=(\text{input units} Ă— \text{output units})+ \text{output units}[/Tex]
Let’s take an example, where the fully connected layer has 128 input units and 64 output units the computed parameters are:
[Tex]Parameters=(128Ă—64)+64=8192+64=8256 [/Tex]
3. Batch Normalization Layers
For batch normalization layers, each feature channel has two parameters (gamma and beta).
[Tex]Parameters=2Ă—\text{num features}[/Tex]
Let’s suppose that batch normalization layer is applied to an output of 64 channels then parameters can be computed as:
[Tex]Parameters = 2 \times 64 =128 [/Tex]
4. Pooling Layers
Pooling layers (e.g., max pooling, average pooling) do not have learnable parameters, so they contribute 0 to the parameter count.
5. Combining All Layers
To find the total number of parameters in the CNN, sum the parameters from all the layers calculated above.
How to calculate the number of parameters in CNN?
Calculating the number of parameters in Convolutional Neural Networks (CNNs) is important for understanding the model complexity, computational requirements, and potential overfitting.
Parameters in CNNs are primarily the weights and biases learned during training. This article will walk you through calculating these parameters in various layers of a CNN.
Table of Content
- Steps of Calculate the number of Parameter in CNN
- 1. Convolutional Layer
- 2. Fully Connected (Dense) Layers
- 3. Batch Normalization Layers
- 4. Pooling Layers
- 5. Combining All Layers
- Example: Calculating the Number of Parameter in CNN
- Parameter Calculation for 3D Convolutions
- Factors Affecting Parameter Calculation
- Conclusion