How to calculate the number of parameters in CNN?

Last Updated : 20 Jun, 2025

Calculating number of parameters in Convolutional Neural Networks (CNNs) is important for understanding model complexity, computational requirements and potential overfitting. Parameters in CNNs are primarily weights and biases learned during training.

Steps to Calculate Number of Parameter in CNN

To calculate the total number of parameters in a 2D convolutional neural network which includes convolutional, fully connected and batch normalization layers while excluding pooling layers as they contribute zero parameters. There steps are:

1. Convolutional Layer

Each convolutional layer has filters or kernels that scan the input image or feature map. The number of parameters depends on:

  • Filter size (height and width)
  • Number of input channels
  • Number of filters (output channels)
  • Bias term (optional, usually 1 per filter)

Parameters= (k_w \times k_h \times C_{in} +1)\times C_{out}

Where:

  • k_w = Filter width
  • k_h = Filter height
  • C_{in} = number of input channels
  • C_{out}= number of filters (output channels)

Here the "+ 1" accounts for the bias term for each filter.

Let's consider an example: if a layer has 32 filters of size 3x3 and input with 3 channels (RGB image). Then its parameters will be: (3Ɨ3Ɨ3+1)Ɨ32=(27+1)Ɨ32=28Ɨ32=896 parameters

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.

Parameters=(\text{input units} Ɨ \text{output units})+ \text{output units}

Let's take an example: if the fully connected layer has 128 input units and 64 output units the computed parameters are: (128Ɨ64)+64=8192+64=8256 Parameters.

3. Batch Normalization Layers

For batch normalization layers each feature channel has two parameters (gamma and beta).

Parameters=2Ɨ\text{num features}

Let's take an example: Suppose that batch normalization layer is applied to an output of 64 channels then parameters can be computed as: 2 x 64 =128 parameters.

4. Pooling Layers

Pooling layers like max pooling, average pooling, etc 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 all the parameters from all the layers calculated above.

Example of Calculating the Number of Parameter in CNN

Consider a simple CNN with the following layers:

  1. Conv layer: 16 filters, 3x3 size, 3 input channels
  2. Conv layer: 32 filters, 3x3 size, 16 input channels
  3. Fully connected layer: 128 input units, 64 output units
  4. Batch normalization after each convolutional layer

Below are the parametrs calculation:

  • Conv Layer 1: (3Ɨ3Ɨ3+1)Ɨ16=(27+1)Ɨ16=448
  • Batch Norm 1: 2Ɨ16=32
  • Conv Layer 2: (3Ɨ3Ɨ16+1)Ɨ32=(144+1)Ɨ32=4640
  • Batch Norm 2: 2Ɨ32=64
  • Fully Connected Layer: (128Ɨ64)+64=8256
  • Total Parameters: 448+32+4640+64+8256=13440

So, the total number of parameters in this simple CNN example is 13,440.

Parameter Calculation for 3-D Convolutions

For a 3D convolutional layer, the number of parameters depends on the size of the filters (kernels), number of filters and the number of input channels.

\text{Parameters} = (k_d \times k_h \times k_w \times C_{in} + 1) \times C_{out}

Where:

  • k_d= Filter depth (size along the depth dimension)
  • k_h = Filter height (size along the height dimension)
  • k_w​ = Filter width (size along the width dimension)
  • C_{in} = number of input channels
  • C_{out} = number of filters (output channels)

The "+ 1" accounts for the bias term for each filter.

Example of Calculating Number of Parameter in 3-D CNN

Consider a CNN with the following layers:

  1. Conv layer: 16 filters, size 3x3x3, 3 input channels
  2. Conv layer: 32 filters, size 3x3x3, 16 input channels
  3. Fully connected layer: 128 input units, 64 output units
  4. Batch normalization after each convolutional layer

Below are the parametrs calculation:

  • Conv Layer 1: (3Ɨ3Ɨ3Ɨ3+1)Ɨ16=82Ɨ16=1312
  • Batch Norm 1: 2Ɨ16=32
  • Conv Layer 2: (3Ɨ3Ɨ3Ɨ16+1)Ɨ32=(432+1)Ɨ32=433Ɨ32=13856
  • Batch Norm 2: 2Ɨ32=64
  • Fully Connected Layer: (128Ɨ64)+64=8256
  • Total Parameters: 1312+32+13856+64+8256=23520

So, the total number of parameters in this simple 3D CNN example is 23,520.

Factors Affecting Parameter Calculation

  1. Filter size: Larger filters have more parameters.
  2. Number of filters: More filters increase the parameters.
  3. Stride and padding: These do not affect the number of parameters but affect the output size.
  4. Number of layers: More layers increase the total parameters.
  5. Input size: Larger input sizes can lead to larger fully connected layers if the output of the final convolutional layer is large.
Comment