Dropout2d
ModuleDropout2d(p: float = 0.5, inplace: bool = False)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:
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[0, 1].
Default: 0.5.inplacebool= FalseTrue, 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 fullH × Wspatial 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
TrueMethods (3)
__init__
→None__init__(p: float = 0.5, inplace: bool = False)Initialise the Dropout2d module. See the class docstring for parameter semantics.
forward
→Tensorforward(x: Tensor)Apply dropout to the input tensor.
Parameters
inputTensorReturns
TensorOutput tensor of the same shape as input; in eval mode this is
the identity.
extra_repr
→strextra_repr()Return a string representation of the layer's configuration.