class

Dropout2d

extendsModule
Dropout2d(p: float = 0.5, inplace: bool = False)
source

Randomly zero entire feature-map channels during training for 4-D inputs.

For image-like inputs of shape (N, C, H, W) a single Bernoulli draw per channel per sample determines whether that entire spatial map is zeroed:

yn,c,:,:={xn,c,:,:1pwith probability 1p0with probability p(training)y_{n,c,:,:} = \begin{cases} \dfrac{x_{n,c,:,:}}{1 - p} & \text{with probability } 1 - p \\[6pt] \mathbf{0} & \text{with probability } p \end{cases} \quad \text{(training)}

Because adjacent pixels in a convolutional feature map are strongly correlated, zeroing individual pixels (as standard Dropout does) has little regularisation effect. Zeroing the entire channel forces the network to not rely on any single feature map.

Parameters

pfloat= 0.5
Probability of zeroing an entire channel. Must be in [0, 1]. Default: 0.5.
inplacebool= False
If True, modify the input in place. Default: False.

Notes

  • Input: (N, C, H, W) — batch of 2-D feature maps.
  • Output: (N, C, H, W) — same shape; zeroed channels are zero across the full H × W spatial extent.

The Bernoulli mask is sampled on the (N, C) axes and broadcast over (H, W). Spatial structure within a channel is therefore fully preserved — only the decision of which channels survive varies.

Dropout : Element-wise scalar dropout. Dropout1d : Channel-wise dropout for 3-D (sequence) inputs. Dropout3d : Channel-wise dropout for 5-D (volumetric) inputs. FeatureAlphaDropout : Channel-wise variant that preserves SELU statistics.

Examples

Typical use after a convolutional layer:
>>> import lucid, lucid.nn as nn
>>> drop2d = nn.Dropout2d(p=0.25)
>>> drop2d.train()
>>> x = lucid.ones(2, 16, 8, 8)    # (N=2, C=16, H=8, W=8)
>>> y = drop2d(x)
>>> y.shape
(2, 16, 8, 8)
>>> # Roughly 25 % of the 16 channels are entirely zero per sample
No-op in eval mode:
>>> drop2d.eval()
>>> y_eval = drop2d(lucid.ones(2, 4, 4, 4))
>>> float(y_eval.sum()) == 128.0
True

Methods (3)

dunder

__init__

None
__init__(p: float = 0.5, inplace: bool = False)
source

Initialise the Dropout2d module. See the class docstring for parameter semantics.

fn

forward

Tensor
forward(x: Tensor)
source

Apply dropout to the input tensor.

Parameters

inputTensor
Input tensor of arbitrary shape.

Returns

Tensor

Output tensor of the same shape as input; in eval mode this is the identity.

fn

extra_repr

str
extra_repr()
source

Return a string representation of the layer's configuration.