Skip to main content
Sign in
Snippets Groups Projects
Commit 4c2b4a1a authored by Falguni Ghosh's avatar Falguni Ghosh
Browse files

Upload New File

parent 65e7e55f
Branches
No related tags found
No related merge requests found
from .Base import BaseLayer
import numpy as np
class Dropout(BaseLayer):
def __init__(self, probability):
super().__init__()
self.probability = probability
self.input_tensor_shape = None
self.output_tensor = None
self.dropout_mask = None
self.error_tensor = None
self.output_error_tensor = None
def forward(self, input_tensor):
if not self.testing_phase:
self.input_tensor_shape = np.shape(input_tensor)
self.dropout_mask = np.random.uniform(0, 1, self.input_tensor_shape) < self.probability
output_tensor = self.dropout_mask * input_tensor * np.float(1 / self.probability)
self.output_tensor = output_tensor
return self.output_tensor.copy()
else:
self.output_tensor = input_tensor
return self.output_tensor.copy()
def backward(self, error_tensor):
self.error_tensor = np.copy(error_tensor)
# output_error_tensor = np.ones(self.input_tensor_shape)
self.output_error_tensor = error_tensor * self.dropout_mask * np.float(1 / self.probability)
return self.output_error_tensor.copy()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment