# Calculate the number of params of a neural network

I'm not clear how the number of params on my Convolutional Network in keras is estimated.

Could you help me to understand this?

Model: "sequential_7"
_________________________________________________________________
Layer (type)                 Output Shape              Param #
=================================================================
conv2d_7 (Conv2D)            (None, 26, 26, 64)        640
_________________________________________________________________
max_pooling2d_7 (MaxPooling2 (None, 13, 13, 64)        0
_________________________________________________________________
flatten_7 (Flatten)          (None, 10816)             0
_________________________________________________________________
dropout_2 (Dropout)          (None, 10816)             0
_________________________________________________________________
dense_14 (Dense)             (None, 128)               1384576
_________________________________________________________________
dense_15 (Dense)             (None, 10)                1290
=================================================================
Total params: 1,386,506
Trainable params: 1,386,506
Non-trainable params: 0


There is not enough information to compute forward the number of parameters of each layer, as we don't know the number of input channels to conv2d_7 or its kernel width. Nevertheless, we can try to guess the missing pieces of information with reasonable assumptions from the number of parameters in each layer, which maybe helps you understand the number of parameter computations:
• conv2d_7 has an output shape with 64 channels. This means that the filter tensor is $$(c \times w \times w + 1) \times 64$$ (the "+ 1" is for the bias), where $$c$$ is the number of input channels and $$w$$ the kernel size. The number of parameters in this layer is 640, which means that $$w \times w \times c + 1= 10$$. I would guess that $$c=1$$ and $$w = 3$$.
• max_pooling2d_7, flatten_7 and dropout_2 don't have trainable parameters (= 0)
• dense_14 has 1384576 parameters and, from the output shape, we know that the projection matrix is $$? \times 128$$. The previous layer has 10816 as output dimensionality. From this, we know that dense_14 has a projection matrix of dimensionality $$10816 \times 128$$ and a bias vector of 128 dimensions (totaling 10816 * 128 + 128 = 1384576)
• dense_15 has 1290 parameters and, from the output shape, we know that the projection matrix is $$? \times 10$$. The previous layer has 128 as output dimensionality. From this, we know that dense_15 has a projection matrix of dimensionality $$128 \times 10$$ and a bias vector of 10 dimensions (totaling 128 * 10 + 10 = 1290).
Adding up the three computed number of parameters gives the total: $$1384576 + 640 + 1290=1386506$$.