#128Convolution — feature-map sizeEasyCNNComputer Vision
Convolution — feature-map size
Background
Sliding a K×K filter over an H×W image (with padding P and stride S) shrinks the spatial size in a predictable way. Per dimension:
For "valid" convolution (, ) this is just .
Problem statement
Implement conv_output_size(N, K, stride, padding) returning the output size along one dimension.
Input
N—int, input size (height or width).K—int, kernel size.stride—int.padding—int.
Output
Returns an int: .
Examples
Example 1 — valid conv
Input: N = 5, K = 3, stride = 1, padding = 0
Output: 3
Explanation: .
Example 2 — same padding keeps the size
Input: N = 5, K = 3, stride = 1, padding = 1
Output: 5
Explanation: .
Constraints
- Use floor division for the stride term.
- Return a plain
int.
Notes
- Stride 2 roughly halves the size; "same" padding ( at stride 1) keeps it unchanged — both are everyday CNN design choices.
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 — valid conv N=5, K=3
- •Reference — same padding keeps size
- •Sample — stride 2 downsamples