How to calculate the number of parameters in CNN when dealing with pictures

Viewed 2733

I get a question as follows:

Suppose you have a 10x10x3 colour image input and you want to stack two convolutional layers with kernel size 3x3 with 10 and 20 filters respectively. How many parameters do you have to train for these two layers?

And I know how to solve a one convolutional layer situation that the number of parameters should be (filter.shape[0]*filter.shape[1]*...*filter.shape[n] + bias) * number of filters.
But I am not sure about how to calculate the number of parameters in multi-layers situations.
Could anyone help me?
Thanks in advance.

2 Answers

After the first layer you have 10 channels instead of 3.

Given the input is 3x3 with depth 3 and 10 filters it results in (3*3*3+1)*10 parameters.

But in the second layer the depth is 10, cause of the first layer. So it becomes (3*3*10+1)*20

(3*3*3+1)*10 + (3*3*10+1)*20 = 2100

Just add all the parameters from each layer. You have the formula for one layer:

(filter.shape[0]filter.shape[1]...*filter.shape[n] + bias) * number of filters

So just calculate this for each layer and add up.

In your example this would give (exlcuding bias):

Layer 1 #params = 3x3x3x10 parameters

Layer 2 #params = 3x3x10x20 parameters

Total = Layer 1 #params + Layer 2 #params

Related