Implementing kernel
C++ engine symbols that back this Python API.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.5Probability of zeroing an entire channel. Must be in
[0, 1].
Default: 0.5.inplacebool= FalseIf
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 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.
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
TrueSee Also
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.
Used by 1
Constructors
1Instance methods
2Return a string representation of the layer's configuration.