4

How can I calculate the area (in the original image) covered by each of the filters in my network?

e.g. Lets say the size of the image is WxW pixels. I am using the following network:

layer 1 : conv :  5x5
layer 2 : pool :  3x3
layer 3 : conv :  5x5
.....
layer N : conv :  5x5

I want to calculate how much area in the original image will be covered by each filter.

e.g. the filter in the layer 1 will cover 5x5 pixels in the original image.

user570593
  • 3,420
  • 12
  • 56
  • 91

1 Answers1

1

A similar problem would be, how many pixels will be covered by each activation? which is essentially the same as, how large an input image has to be in order to produce exactly one activation in a layer?

Say the filter size and stride of a layer is k and s, the size of the input is x*x, we have (((x-k1+1)/s1-k2+1)/s2.../sn)=1, and x can be solved easily.

The original question is equivalent to, how large an input image has to be in order to produce exactly one activation in a layer, without considering the stride of the last layer?

So the answer is x/sn, which should be computed by the following pseudocode

x = layer[n].k
from i = n-1 to 1
   x = x*layer[i].s + layer[i].k - 1

the total amount of pixels is then x*x.

In your example, the sum_1d for the first layer is 5, for the second layer is 5*1+3-1=7, the third is 5*3+2+4=21 (I'm assuming the pooling layer is non-overlapping, s=3)..

You can verify this by doing the reverse, say the input is 21*21, after the first layer it is 17*17, after pooling it is (17-2)/3=5 (actually 16*16 and 15*15 will give the same result), which fits exactly into one filter in the third layer.

dontloo
  • 10,067
  • 4
  • 29
  • 50
  • Thanks. Lets assume the image size is 487, ks_arr = [11, 7, 11, 7], step_arr = [3, 3, 3, 3]. Based on your calculations the last layer will cover 77 pixels. But if I reverse it the final image size will be 4x4. 487/4 ~= 120. So I feel the last filter should cover ~120 pixels. Am I correct? – user570593 Apr 15 '16 at 13:52
  • @user570593 right.. really sorry for the wrong answer, i'll try to fixed it – dontloo Apr 15 '16 at 14:10
  • Thanks for the answer. I feel layer[i-1].s has to be multiplied by some value. But I am confused. – user570593 Apr 15 '16 at 14:11
  • Thanks, but I am not sure whether this is correct. The filter sizes are going to be applied on images with different sizes (at different layers the image sizes are going to be different). So summing the filter sizes may not be correct. What do you think? – user570593 Apr 15 '16 at 15:25
  • @user570593 for the ks_arr = [11, 7, 11, 7], step_arr = [3, 3, 3, 3] example, `len_1d` of the forth layer should be, ((((7*3+10)*3+6)*3+10)=307, do it reversely, after the first layer, (307-10)/3=99, after the second (99-6)/3=31, after the third, (31-10)/3=7, which will fit into a 7*7 filter. – dontloo Apr 15 '16 at 16:10
  • @user570593 i've added some explanation, I hope it makes sense. – dontloo Apr 15 '16 at 17:30
  • Thanks for the detail answer. – user570593 Apr 18 '16 at 10:57