#140Hierarchy — the receptive field grows with depthEasy

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:

RF=1+num_layers×(k1)\text{RF} = 1 + \text{num\_layers} \times (k - 1)

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_layersint 0\ge 0, number of stacked conv layers.
  • kernel_sizeint 1\ge 1, the kernel width.

Output

Returns an int: 1+num_layers(k1)1 + \text{num\_layers}\,(k - 1).

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: 1+3×2=71 + 3\times2 = 7.

Constraints

  • Use 1+num_layers(k1)1 + \text{num\_layers}\,(k - 1).
  • num_layers = 0 gives 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