Last active
May 30, 2020 17:19
-
-
Save SkalskiP/02f293d91662c9f1c2090ae7db486d1b to your computer and use it in GitHub Desktop.
Max pooling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def forward_pass(self, a_prev: np.array) -> np.array: | |
self._shape = a_prev.shape | |
n, h_in, w_in, c = a_prev.shape | |
h_pool, w_pool = self._pool_size | |
h_out = 1 + (h_in - h_pool) // self._stride | |
w_out = 1 + (w_in - w_pool) // self._stride | |
output = np.zeros((n, h_out, w_out, c)) | |
for i in range(h_out): | |
for j in range(w_out): | |
h_start = i * self._stride | |
h_end = h_start + h_pool | |
w_start = j * self._stride | |
w_end = w_start + w_pool | |
a_prev_slice = a_prev[:, h_start:h_end, w_start:w_end, :] | |
self._save_mask(x=a_prev_slice, cords=(i, j)) | |
output[:, i, j, :] = np.max(a_prev_slice, axis=(1, 2)) | |
return output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment