Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 6

Understanding Receptive Fields in CNNs

Recommended resources

Hello! In our last lesson, we traced the entire journey of data through a CNN, watching how an image is transformed into a rich hierarchy of feature maps. We saw that deeper layers capture more abstract and complex patterns. This naturally leads to a crucial question: how much of the original input image does a single feature in a deep layer actually "see"?

This lesson concludes our first module by addressing that very question. We'll explore the concept of the receptive field, which is fundamental to understanding the spatial context available to your network. Today's learning outcome is to: Explain the concept of a receptive field and how it expands in deeper layers of a CNN. By the end of this lesson, you will understand what a receptive field is, why its size matters, how to calculate it, and the important distinction between its theoretical size and its practical, effective size.

What is a Receptive Field?

The concept of a receptive field is borrowed from biology, where it describes the specific region of sensory space (e.g., an area on the retina) that stimulates a neuron. In the context of CNNs, the definition is analogous.

Understanding the receptive field of deep convolutional ...

This article from AI Summer provides a clear and concise introduction to the receptive field, starting with its biological origins and translating it to the world of deep learning.

Please read the first two sections of the article, up to the heading "Why do we care about the receptive field of a convolutional network?". Pay attention to the core definition presented in the text, starting from the biological analogy and then the deep learning definition.

As the article explains, the receptive field of a feature in a CNN is the specific region of the input image that affects the value of that feature. A neuron in the first convolutional layer has a receptive field equal to its kernel size (e.g., 3x3). But what about a neuron in a deeper layer? Its receptive field with respect to the original input image is much larger.

The size of the receptive field is critically important. For a network to identify a large object, the receptive fields of its final features must be large enough to encompass the entire object and its surrounding context. For tasks like semantic segmentation, which is central to your project goal, each pixel's prediction should be informed by a large contextual window to be accurate. As you can see in the graph in the "Why do we care..." section of the article you just read, there's a clear correlation between larger receptive fields and higher classification accuracy on complex datasets like ImageNet.


How the Receptive Field Expands

The receptive field grows as we pass data through successive layers of the network. Each layer builds upon the receptive fields of the layer before it. This expansion happens primarily through two mechanisms: stacking convolutional layers and using sub-sampling layers (like max pooling or convolutions with a stride greater than 1).

Let's visualize this. The image below shows how the receptive field expands across two convolutional layers. A single pixel in Layer 1 sees a 3x3 patch of the input Layer 0. A single pixel in Layer 2 sees a 3x3 patch of Layer 1. But because each of those pixels in Layer 1 already saw a 3x3 input patch, the pixel in Layer 2 is effectively influenced by a larger 5x5 region of the original input.

This diagram illustrates the growth of the receptive field. An output feature (red dot) in a deeper layer is influenced by a progressively larger area of the original input. The formulas shown calculate various properties, including the receptive field size (`r`).

To see this process in motion, the following animated video provides an excellent visual demonstration.

CNN Receptive Field | Deep Learning Animated

The video "CNN Receptive Field | Deep Learning Animated" by Deepia provides a clear, step-by-step visualization of how the receptive field expands through the layers of a CNN.

Watch the first two parts of the video. The first part, "What is a receptive field?", provides a great intuitive introduction. The second part, the expansion example, animates the process we just described, showing how a 3-layer CNN with 3x3 filters achieves a 7x7 receptive field.


Calculating the Theoretical Receptive Field

Given your background, you'll appreciate that we can move beyond intuitive visualizations to a precise mathematical formulation. The size of the receptive field isn't a mystery; it can be calculated exactly from the network's architecture. The canonical resource for this is the Distill.pub article "Computing Receptive Fields of Convolutional Neural Networks."

Computing Receptive Fields of Convolutional Neural ...

This article provides a rigorous mathematical derivation for the receptive field size. We will focus on the section for single-path networks, which builds the foundation.

Please read the section "Single-path networks," focusing on the subsection "Computing receptive field size." Start by understanding the initial setup. Then, follow the derivation that leads to the general recurrence equation for r_l-1. Finally, focus on the closed-form solution presented in Equation 2. This is the key takeaway.

The closed-form solution from the article is a powerful tool. For a network with layers, the receptive field size with respect to the input is given by:

Let's break this down:

  • is the kernel size of layer .
  • is the stride of layer .
  • The term represents the "new" area added by a convolution at layer .
  • The product is the cumulative stride up to layer . It acts as a multiplier, accounting for how much the "space" has been scaled by previous strided convolutions or pooling layers. A stride at an early layer makes any subsequent kernel effectively cover a much larger area of the input.
  • The summation accumulates these contributions from all layers, and the +1 accounts for the initial pixel.

You'll notice that pooling layers aren't explicitly in the formula. A pooling layer with kernel size and stride is treated just like a convolutional layer with the same parameters for the purpose of this calculation.


How to Increase the Receptive Field

As we've seen, a large receptive field is often desirable. There are several architectural choices you can make to increase it:

  1. Stack more convolutional layers: This is the most straightforward way. As the formula shows, each layer adds to the receptive field size. The growth is linear if all strides are 1.
  2. Use sub-sampling: Introducing max pooling layers or using convolutions with a stride greater than 1 increases the receptive field multiplicatively. This is a very efficient way to rapidly expand the field.
  3. Use dilated convolutions: This is a particularly powerful technique that is highly relevant to your goal. A dilated (or atrous) convolution introduces gaps into the kernel, allowing it to cover a larger area without increasing the number of parameters or the computational cost. Crucially, it does this without the down-sampling that comes with pooling or strided convolutions, thus preserving spatial resolution. This is vital for dense prediction tasks like semantic segmentation.

The following video clip provides an excellent explanation of dilated convolutions.

CNN Explained Visually: Padding, Stride, Pooling, Receptive Fields, Dilation & Layer Architecture

This video, "CNN Explained Visually," has a very clear segment on dilated convolutions that demonstrates how they work.

Please watch the section on dilated convolutions from this timestamp. Pay close attention to how the effective kernel size is increased without adding parameters, and how this directly translates to a larger receptive field.

This concept will be central when we discuss the DeepLabV3 architecture in the next module.


Theoretical vs. Effective Receptive Field

So far, we have only discussed the theoretical receptive field—the maximum possible region of the input that could influence an output feature. However, research has shown that in practice, not all pixels within this theoretical boundary contribute equally. This leads to the concept of the effective receptive field (ERF).

The ERF is the region that actually has a significant influence on the output. It has been shown experimentally that the ERF often has a Gaussian shape, meaning pixels at the center of the receptive field have a much larger impact than pixels at the edges.

Visualization of the effective receptive field (ERF) for CNNs of varying depths (5, 10, 20, 40 layers). Notice how the ERF is much smaller than the theoretical RF and tends towards a Gaussian distribution, especially in deeper networks. The training process (Random + ReLU) further concentrates this field.

The final part of the Deepia video you watched earlier provides an excellent summary of this crucial distinction.

CNN Receptive Field | Deep Learning Animated

This final segment of the "CNN Receptive Field" video explains the difference between the theoretical and effective receptive fields.

Please re-watch the video from this timestamp. It explains how the ERF can be measured and how it is influenced by factors like random weight initialization and the training process itself.

The key insight is that the ERF is often significantly smaller than the theoretical RF. This means that even if your network theoretically has a receptive field large enough to see an entire object, it may in practice only be focusing on a small central part. This is an active area of research, with architectural designs like dilated convolutions being one way to help ensure a larger area is effectively utilized.


Conclusion

This lesson concludes our foundational module on neural networks for image data. We've gone from the basic building blocks to a sophisticated understanding of how a CNN perceives spatial information.

Key Takeaways:

  • The receptive field is the region of the input image that influences a single feature in a CNN layer.
  • It expands in deeper layers by stacking convolutions and using sub-sampling (pooling or strides), allowing the network to learn a hierarchy of features from local to global.
  • The theoretical receptive field can be calculated precisely based on the kernel sizes and strides of the network's layers.
  • Techniques like dilated convolutions can increase the receptive field exponentially without losing spatial resolution, which is critical for segmentation tasks.
  • The effective receptive field (ERF) represents the area that practically contributes to an output and is often smaller and more centrally-focused than its theoretical counterpart.

We have now established a solid theoretical foundation. In the next module, we will apply these concepts directly to your project goal. We'll begin by justifying why semantic segmentation is the right approach for localized smile enhancement and start exploring the powerful encoder-decoder architectures that make it possible.