Conv2D Output Shape
Medium
~12 min
code completion
Convolutional Output Shape
Before implementing a convolution, you need to know the output dimensions.
For a 2D convolution with no padding and stride :
where , are the filter (kernel) dimensions.
Example: 7×7 input, 3×3 filter, stride 2 → , so output is 3×3.
Your task:
Implement conv2d_output_shape(input_h, input_w, filter_h, filter_w, stride) that returns a tuple (out_h, out_w).
Example Tests
7x7 input, 3x3 filter, stride 1 → 5x5
Input: {"stride":1,"input_h":7,"input_w":7,"filter_h":3,"filter_w":3}
Expected: [5,5]
7x7 input, 3x3 filter, stride 2 → 3x3
Input: {"stride":2,"input_h":7,"input_w":7,"filter_h":3,"filter_w":3}
Expected: [3,3]
Non-square input
Input: {"stride":1,"input_h":10,"input_w":6,"filter_h":3,"filter_w":3}
Expected: [8,4]