Dropout2d¶
- class torch.nn.Dropout2d(p=0.5, inplace=False)[source]¶
Randomly zero out entire channels.
A channel is a 2D feature map, e.g., the -th channel of the -th sample in the batched input is a 2D tensor .
Each channel will be zeroed out independently on every forward call with probability
p
using samples from a Bernoulli distribution.Usually the input comes from
nn.Conv2d
modules.As described in the paper Efficient Object Localization Using Convolutional Networks , if adjacent pixels within feature maps are strongly correlated (as is normally the case in early convolution layers) then i.i.d. dropout will not regularize the activations and will otherwise just result in an effective learning rate decrease.
In this case,
nn.Dropout2d()
will help promote independence between feature maps and should be used instead.- Parameters
Warning
Due to historical reasons, this class will perform 1D channel-wise dropout for 3D inputs (as done by
nn.Dropout1d
). Thus, it currently does NOT support inputs without a batch dimension of shape . This behavior will change in a future release to interpret 3D inputs as no-batch-dim inputs. To maintain the old behavior, switch tonn.Dropout1d
.- Shape:
Input: or .
Output: or (same shape as input).
Examples:
>>> m = nn.Dropout2d(p=0.2) >>> input = torch.randn(20, 16, 32, 32) >>> output = m(input)