Computing Receptive Fields of Convolutional Neural Networks: From Mathematical Derivation to Open-Source Tools
Understanding how output features map back to input signals is crucial in the development and debugging of deep learning models.
In the development and debugging of deep learning models, understanding how output features map back to input signals is crucial. This article, titled "Computing Receptive Fields of Convolutional Neural Networks" by André Araujo, Wade Norris, and Jack Sim, published on Distill in 2019, systematically addresses the problem of calculating "receptive fields" in Convolutional Neural Networks (CNNs). The receptive field is defined as the size of the input region that produces a specific output feature, serving as a key parameter connecting internal abstract representations within the network to raw data.
The article first provides closed-form solutions for single-path networks (such as AlexNet or VGG). The authors derive the recursive formula $r_{l-1} = s_l \cdot r_{l} + (k_l - s_l)$ and the final closed-form expression $r_0 = \sum_{l=1}^{L} ((k_l-1)\prod_{i=1}^{l-1} s_i) + 1$. This derivation not only simplifies the tedious process of manual calculation but also clarifies the mechanism by which stride and kernel size cumulatively affect the receptive field. For example, when the stride of a certain layer is greater than 1, the receptive field regions of all layers below it expand proportionally. Additionally, the article details how to precisely locate the coordinates of the region in the input image that generates a specific output feature, which is particularly critical for tasks requiring multi-scale recognition, such as object detection.
Subsequently, the article extends the theory to modern multi-path architectures (such as ResNet or Inception). These networks have multiple paths from input to output, making receptive field calculations complex and potentially leading to alignment issues. The authors propose an algorithm to handle the calculation of receptive field sizes and positions in arbitrary computational graphs, filling the gap left by previous works that focused only on simple single-path networks. To verify these theories and facilitate researcher usage, the team developed and open-sourced a toolkit integrated into the TensorFlow codebase. This library automatically performs the complex calculations described in the text, avoiding the risk of errors associated with manual derivation.