Skip to content

Commit c354b9b

Browse files
committed
Add GaussianDropout
1 parent 14b0148 commit c354b9b

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

keras/layers/noise.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,26 @@ def get_output(self, train=False):
2020

2121
def get_config(self):
2222
return {"name":self.__class__.__name__,
23-
"sigma":self.sigma}
23+
"sigma":self.sigma}
24+
25+
class GaussianDropout(Layer):
26+
'''
27+
Multiplicative Gaussian Noise
28+
Reference:
29+
Dropout: A Simple Way to Prevent Neural Networks from Overfitting
30+
Srivastava, Hinton, et al. 2014
31+
'''
32+
def __init__(self, p):
33+
super(GaussianDropout,self).__init__()
34+
self.p = p
35+
36+
def get_output(self, train):
37+
X = self.get_input(train)
38+
if train:
39+
# self.p refers to drop probability rather than retain probability (as in paper) to match Dropout layer syntax
40+
X *= srng.normal(size=X.shape, avg = 1., std=T.sqrt(self.p/(1-self.p)), dtype=theano.config.floatX)
41+
return X
42+
43+
def get_config(self):
44+
return {"name":self.__class__.__name__,
45+
"p":self.p}

0 commit comments

Comments
 (0)