PIXELBANKv8.2.1
Menu

Padding for Same Convolution

Problem Statement

Determine the padding PP required to keep the output size equal to the input size (assuming stride S=1).

Background

To maintain spatial dimensions (O=IO = I) with stride 1, we solve:

I=IF+2P+1I = I - F + 2P + 1

This gives us: P=F12P = \frac{F - 1}{2}

This is called "same" padding because the output has the same spatial dimensions as the input.

Your Task

Write a function calculate_same_padding(filter_size) returning the integer padding amount. Assume the filter size is always odd.

Output Format

Return an integer representing the padding needed for "same" convolution.

Example:

Input:
filter_size=5
Output:
2
Reasoning:

2P = F - 1 → 2P = 4 → P = 2

Constraints:

  • filter_size is always an odd number
  • 1 <= filter_size <= 15
Editor

Test Results

0/0
Run code to see test results.