Shortcuts

Source code for nets.nn.modules.dropout

"""
Define a ``Dropout`` layer.
"""

from .module import Module
from ..functional import dropout


[docs]class Dropout(Module): """ Applies a ``dropout`` to an input ``Tensor`` with probability ``prob``. The effect of this layer is to zeros elements of the incoming tensors, and cancel some neighbours effect / interactions from one layer to another. """ def __init__(self, prob=0.5): super().__init__() self.prob = prob
[docs] def forward(self, inputs): scale = 1 / (1 - self.prob) if self.prob < 1 else 0 return scale * dropout(inputs, self.prob)
# TODO: add a manual back-propagation for the dropout class # NOTE: but with autograd system, no need to worry about this
[docs] def backward(self, outputs): raise NotImplementedError

Docs

Access comprehensive developer documentation for Nets

View Docs

Tutorials

Get beginners tutorials and create state-of-the-art models

View Tutorials

Resources

Check the GitHub page and contribute to the project

View GitHub