Skip to content

Instantly share code, notes, and snippets.

@SkalskiP
Created May 23, 2020 16:44
Show Gist options
  • Save SkalskiP/435de1551c6c28e6cb03107ab04ab810 to your computer and use it in GitHub Desktop.
Save SkalskiP/435de1551c6c28e6cb03107ab04ab810 to your computer and use it in GitHub Desktop.
Dropout forward and backward
def forward_pass(self, a_prev: np.array, training: bool) -> np.array:
if training:
self._mask = (np.random.rand(*a_prev.shape) < self._keep_prob)
return self._apply_mask(a_prev, self._mask)
else:
return a_prev
def backward_pass(self, da_curr: np.array) -> np.array:
return self._apply_mask(da_curr, self._mask)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment