Source code for tensorlayer.layers.dropout

#! /usr/bin/python
# -*- coding: utf-8 -*-

import tensorflow as tf
from tensorlayer import logging
from tensorlayer.decorators import deprecated_alias
from tensorlayer.layers.core import Layer

# from tensorlayer.layers.core import LayersConfig

__all__ = [

[docs]class Dropout(Layer): """ 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. seed : int or None The seed for random dropout. name : None or str A unique layer name. """ def __init__(self, keep, seed=None, name=None): #"dropout"): super(Dropout, self).__init__(name) self.keep = keep self.seed = seed self._built = True"Dropout %s: keep: %f " % (, self.keep)) def __repr__(self): s = ('{classname}(keep={keep}') if is not None: s += ', name=\'{name}\'' s += ')' return s.format(classname=self.__class__.__name__, **self.__dict__) def build(self, inputs_shape=None): pass # @tf.function def forward(self, inputs): if self.is_train: outputs = tf.nn.dropout(inputs, rate=1 - (self.keep), seed=self.seed, else: outputs = inputs return outputs