Skip to content

Instantly share code, notes, and snippets.

@SkalskiP
Last active May 23, 2020 12:03
Show Gist options
  • Save SkalskiP/0b591d6283c1c0b2f6a570f0a9f1444d to your computer and use it in GitHub Desktop.
Save SkalskiP/0b591d6283c1c0b2f6a570f0a9f1444d to your computer and use it in GitHub Desktop.
Convolution forward
def forward_pass(self, a_prev: np.array) -> np.array:
n, h_in, w_in, _ = a_prev.shape
_, h_out, w_out, _ = output_shape
h_f, w_f, _, n_f = self._w.shape
output_shape = self.calculate_output_dims(input_dims=a_prev.shape)
output = np.zeros(output_shape)
for i in range(h_out):
for j in range(w_out):
h_start, w_start = i, j
h_end, w_end = h_start + h_f, w_start + w_f
output[:, i, j, :] = np.sum(
a_prev[:, h_start:h_end, w_start:w_end, :, np.newaxis] *
self._w[np.newaxis, :, :, :],
axis=(1, 2, 3)
)
return output + self._b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment