def __init__(self, rng, input, dropout_rate=0.5):
"""
input: output of last layer
"""
self.input = input
self.dropout_rate = dropout_rate
srng = T.shared_randomstreams.RandomStreams(rng.randint(999999))
if self.dropout_rate > 0:
# p=1-p because 1's indicate keep and p is prob of dropping
mask = srng.binomial(n=1, p = 1-self.dropout_rate, size=self.input.shape)
# The cast is important because
# int * float32 = float64 which pulls things off the gpu
self.output = self.input * T.cast(mask, theano.config.floatX)
else:
self.output = input
评论列表
文章目录