oneflow.nn.Dropout2d

class oneflow.nn.Dropout2d(p: float = 0.5, inplace: bool = False, generator=None)

Randomly zero out entire channels (a channel is a 2D feature map, e.g., the \(j\)-th channel of the \(i\)-th sample in the batched input is a 2D tensor :math:` ext{input}[i, j]`). Each channel will be zeroed out independently on every forward call with probability p using samples from a Bernoulli distribution.

The documentation is referenced from: https://pytorch.org/docs/1.10/generated/torch.nn.Dropout2d.html.

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, oneflow.nn.Dropout2d() will help promote independence between feature maps and should be used instead.

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

  • inplace (bool, optional) – If set to True, will do this operation in-place

Shape:
  • Input: \((N, C, H, W)\) or \((C, H, W)\).

  • Output: \((N, C, H, W)\) or \((C, H, W)\) (same shape as input).

For example:

>>> import numpy as np
>>> import oneflow as flow

>>> m = flow.nn.Dropout2d(p=0)
>>> arr = np.array(
...    [
...        [-0.7797, 0.2264, 0.2458, 0.4163],
...        [0.4299, 0.3626, -0.4892, 0.4141],
...        [-1.4115, 1.2183, -0.5503, 0.6520],
...    ]
... )
>>> x = flow.Tensor(arr)
>>> y = m(x)
>>> y 
tensor([[-0.7797,  0.2264,  0.2458,  0.4163],
        [ 0.4299,  0.3626, -0.4892,  0.4141],
        [-1.4115,  1.2183, -0.5503,  0.6520]], dtype=oneflow.float32)