2-D Convolution Forward Pass

medium
Unit 10 · CNNs0/3 to milestone

Implement the forward pass of a 2-D convolution layer (cross-correlation, as frameworks use).

conv2d(x, w, b, stride=1, padding=0):

  • x: input of shape (C_in, H, W)
  • w: kernels of shape (C_out, C_in, KH, KW)
  • b: bias of shape (C_out,)
  • Zero-pad the height and width by padding on each side, then slide each kernel with the given stride.

Output shape (C_out, H_out, W_out) with Hout=⌊(H+2p−KH)/s⌋+1H_{out} = \lfloor (H + 2p - KH)/s \rfloor + 1 (and the same for width). Loop over output positions if you like, but vectorise over channels.

#cnn#numpy#vision2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
2-D Convolution Forward Pass · TechGradify