PIXELBANKv9.1.0
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=Iβˆ’F+2P+1I = I - F + 2P + 1

This gives us: P=Fβˆ’12P = \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
solution.py

Test Results

0/0
Run code to see test results.
Padding for Same Convolution - Easy | PixelBank