How to count the parameters in a convolution layer? I'm preparing for an exam in Computer Vision. I came across with the following question from one of the exams:

What is the number of parameters of a convolution layer in a neural network, when the input size is $100 \times100 \times128$ and the output $100 \times100 \times256$, the convolution size is $3 \times3$, with and without the bias?

I noticed that they really like to ask this type of questions, although not sure what does it teach. I understand the general idea of the CNN architecture but eveytime they ask me to count, I get confuse.
I solved the following similar question:

What is the number of parameters of a linear layer in a neural network) called both fully-connected and dense) when the vector size at input 128 and output 256 with and without the bias?

My suggested solution:

Without bias:
$$\#\text{params}=|\text{input}|\cdot|\text{output}|=128\cdot256=32,768$$
With bias:
$$\#\text{params}=|\text{input}|\cdot\left(|\text{output}|+1\right)=128\cdot(256+1)=128\cdot257=32,896$$

How to count the parameters in the convolution layer above? In which other layers this "count parameters" question can pop up? (Pooling, etc.).

In a CNN layer, the number of parameters is determined by the kernel size and the number of kernels. The size of the input and output in the dimensions being convolved do not affect the number of parameters. So, in a standard 2-D CNN layer with 3-D input/output, only the 3rd dimension (often referred to as the channels) of the input/output matters. The number of input channels determines the 3rd dimension size of your kernels and the number of output channels is the number of kernels. The number of parameters in each kernel is simply the specified kernel size times the number of input channels (then $+1$ for the bias if using it), then multiply this by the number of kernels to get the total number of parameters.
In this case, your convolutional kernels are $3\times3\times128$ and you have $256$ of them, so:
Without bias:
$$\begin{aligned}\#params&=kernel\_size\times|input\_channels|\times|output\_channels|
\\&=3\times3\times128\times256
\\&=294912\end{aligned}$$
With bias:
$$\begin{aligned}\#params&=(kernel\_size\times|input\_channels|+1)\times|output\_channels|\\&=(3\times3\times128+1)\times256\\&=295168\end{aligned}$$
