Rate this Page

Dropout2d#

classtorch.nn.modules.dropout.Dropout2d(p=0.5,inplace=False)[source]#

Randomly zero out entire channels.

A channel is a 2D feature map,e.g., thejj-th channel of theii-th sample in thebatched input is a 2D tensorinput[i,j]\text{input}[i, j].

Each channel will be zeroed out independently on every forward call withprobabilityp using samples from a Bernoulli distribution.

Usually the input comes fromnn.Conv2d modules.

As described in the paperEfficient 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. dropoutwill not regularize the activations and will otherwise just resultin an effective learning rate decrease.

In this case,nn.Dropout2d() will help promote independence betweenfeature maps and should be used instead.

Parameters
  • p (float,optional) – probability of an element to be zero-ed.

  • inplace (bool,optional) – If set toTrue, will do this operationin-place

Warning

Due to historical reasons, this class will perform 1D channel-wise dropoutfor 3D inputs (as done bynn.Dropout1d). Thus, it currently does NOTsupport inputs without a batch dimension of shape(C,H,W)(C, H, W). Thisbehavior will change in a future release to interpret 3D inputs as no-batch-diminputs. To maintain the old behavior, switch tonn.Dropout1d.

Shape:

Examples:

>>>m=nn.Dropout2d(p=0.2)>>>input=torch.randn(20,16,32,32)>>>output=m(input)
forward(input)[source]#

Runs the forward pass.

Return type

Tensor