The :class:`Dropout` class is a noise layer which randomly set some activations to zero according to a keeping probability. Parameters ---------- keep : float The keeping probability. The lower the probability it is, the more activations are set to zero. see
| 15 | |
| 16 | |
| 17 | class Dropout(Layer): |
| 18 | """ |
| 19 | The :class:`Dropout` class is a noise layer which randomly set some |
| 20 | activations to zero according to a keeping probability. |
| 21 | |
| 22 | Parameters |
| 23 | ---------- |
| 24 | keep : float |
| 25 | The keeping probability. |
| 26 | The lower the probability it is, the more activations are set to zero. |
| 27 | seed : int or None |
| 28 | The seed for random dropout. |
| 29 | name : None or str |
| 30 | A unique layer name. |
| 31 | |
| 32 | """ |
| 33 | |
| 34 | def __init__(self, keep, seed=None, name=None): #"dropout"): |
| 35 | super(Dropout, self).__init__(name) |
| 36 | self.keep = keep |
| 37 | self.seed = seed |
| 38 | |
| 39 | self.build() |
| 40 | self._built = True |
| 41 | |
| 42 | logging.info("Dropout %s: keep: %f " % (self.name, self.keep)) |
| 43 | |
| 44 | def __repr__(self): |
| 45 | s = ('{classname}(keep={keep}') |
| 46 | if self.name is not None: |
| 47 | s += ', name=\'{name}\'' |
| 48 | s += ')' |
| 49 | return s.format(classname=self.__class__.__name__, **self.__dict__) |
| 50 | |
| 51 | def build(self, inputs_shape=None): |
| 52 | pass |
| 53 | |
| 54 | # @tf.function |
| 55 | def forward(self, inputs): |
| 56 | if self.is_train: |
| 57 | outputs = tf.nn.dropout(inputs, rate=1 - (self.keep), seed=self.seed, name=self.name) |
| 58 | else: |
| 59 | outputs = inputs |
| 60 | return outputs |
no outgoing calls
searching dependent graphs…