3
votes

I couldn't find the right formula to compute the number of MACs in one Convolutional layer in a CNN. I tried this formula from Quora

[((H-K+S) /S) *((W-L+S)/S)) *C*M*N] 

Where : HW size of input feature map; KL size of filter S stride C channels of the input M Output feature map N number of input feature map

I took an example : 1 input image 5x5x1 1 filter 3x3x1 Then I did a naïve calculation, I obtained 81 MACs. But when I used the above mentioned formula ai obtained 9.

I think that there is something that I didn't understand.

Thanks in advance

1
And what exactly is a MAC?desertnaut
A MAC is a multiply and accumulate operation since we're are taking about convolutions in CNNOnward

1 Answers

4
votes

Say you have these parameters:
K is you kernel width and height
C_in is number of input channels
C_out is number of output channels
H_out and W_out height and width of the output matrix respectively

Then, you need (K^2) * C_in MAC operations to compute each output feature map and you will have H_out * W_out * C_out of these output feature maps. Then total MACs would be:

(K^2) * C_in * H_out * W_out * C_out