#140Hierarchy — the receptive field grows with depthEasyCNNComputer Vision
Hierarchy — the receptive field grows with depth
Background
A CNN builds a hierarchy because each layer sees a little more context than the last. For a stack of num_layers convolutions with kernel size k and stride 1, the receptive field (how many input pixels one deep neuron depends on, in 1-D) is:
Deeper neurons integrate larger regions — which is why early layers see edges and deep layers see whole objects.
Problem statement
Implement receptive_field(num_layers, kernel_size) returning the 1-D receptive field of a stride-1 conv stack.
Input
num_layers—int, number of stacked conv layers.kernel_size—int, the kernel width.
Output
Returns an int: .
Examples
Example 1 — one 3×3 conv sees 3 pixels
Input: num_layers = 1, kernel_size = 3
Output: 3
Example 2 — three stacked 3×3 convs
Input: num_layers = 3, kernel_size = 3
Output: 7
Explanation: .
Constraints
- Use .
num_layers = 0gives a receptive field of 1 (a single pixel).- Return a plain
int.
Notes
- Two stacked 3×3 convs (RF 5) cover the same field as one 5×5 conv but with fewer parameters — a key trick behind VGG-style nets.
Python
Loading...
▶ Run executes the 3 visible sample tests below in your browser. Submit runs the full suite — including hidden tests — on the server for an official verdict.
- •Example one 3x3 conv sees 3 pixels
- •Reference three stacked 3x3 convs
- •Sample two 5x5 convs