All problems
Conv Output Size
Problem
Compute the spatial output size of a strided 2D convolution.
out = (n + 2 * pad - k) // stride + 1 for each dimension. Given height h, width w, kernel size k, stride and pad, return [out_h, out_w].
Hint
Padding adds 2 * pad to each side before the kernel slides.
Test cases
case 1
in: [28,28,3,1,0]
expected: [26,26]
case 2
in: [32,32,3,1,1]
expected: [32,32]
case 3
in: [28,28,5,2,0]
expected: [12,12]
case 4
in: [7,7,3,2,1]
expected: [4,4]
Starter codePython
def conv_output_size(h, w, k, stride, pad):
# Your code here
pass4 test cases · run your code against them in the editor