How to calculate receptive field size?

1) It is the size of the area of pixels that impact the output of the last convolution.

2) For each convolution and pooling operation, compute the size of the output. Now find the input size that results in an output size of 1x1. Thats the size of the receptive field

3) You don't need to use a library to do it. For every 2x2 pooling the output size is reduced by half along each dimension. For strided convolutions, you also divide the size of each dimension by the stride. You may have to shave off some of the dimension depending on if you use padding for your convolutions. The simplest case is to use padding = floor(kernel size/2), so that a convolution dose not have any extra change on the output size.


UPDATE Dec 11, 2019:

The TF library was moved to https://github.com/google-research/receptive_field

See also the Distill paper "Computing Receptive Fields of Convolutional Neural Networks": https://distill.pub/2019/computing-receptive-fields/

OLD:

Tensorflow now supports receptive field computation, by simply using tf.contrib.receptive_field

See https://github.com/tensorflow/tensorflow/tree/master/tensorflow/contrib/receptive_field for details.


Here is another way to computes receptive field directly. Stackoverflow does not support math formula, for a more readable version, please refer to Calculating Receptive Field of CNN

The receptive field (RF) $l_k$ of layer $k$ is:

$$ l_k = l_{k-1} + ((f_k - 1) * \prod_{i=1}^{k-1}s_i) $$

where $l_{k-1}$ is the receptive field of layer $k-1$, $f_k$ is the filter size (height or width, but assuming they are the same here), and $s_i$ is the stride of layer $i$.

The formula above calculates receptive field from bottom up (from layer 1). Intuitively, RF in layer $k$ covers $(f_k - 1) * s_{k-1}$ more pixels relative with layer $k-1$. However, the increment needs to be translated to the first layer, so the increments is a factorial --- a stride in layer $k-1$ is exponentially more strides in the lower layers.

Hope this is helpful.