How to compute number of weights of CNN?
Calculating parameter number in a CNN is very straightforward.
CNN is composed of different filters which is essentially a 3d tensor. CNN weights are shared meaning they are used multiple times and reused in different locations. Each layer have n tensors each with dimension w * h * c where w = width, h = height, c = channels (the input channel size), therefore getting param_no = w * h * c * n. There is also a bias for each output channel, so param_no_bias = n. At the end the parameter number is calculated with: n * w * h * c + n. See more about this in hear: Article
The pooling layer does not have a weight, it only has hyperparameters. You may have confused the two. There are hyperparameters for the stride, the factor and etc. These are predefined and not trainable.
For a keras API, @pasabaporaqui has mentioned https://stackoverflow.com/a/35827171/4886927 which definitely works.
Hope I can help you.