Dropout1d
ModuleDropout1d(p: float = 0.5, inplace: bool = False)Randomly zero entire channels during training for 3-D inputs.
Extends the dropout idea from individual elements to entire channels
(feature maps) for sequence data of shape (N, C, L). A single
Bernoulli draw per channel per sample determines whether that channel
is zeroed across its entire length:
This is more aggressive than element-wise Dropout and is
appropriate when neighbouring positions along the L axis are highly
correlated (as they are in the output of a 1-D convolution), so that
zeroing a single element would not provide enough regularisation signal.
Parameters
pfloat= 0.5[0, 1].
Default: 0.5.inplacebool= FalseTrue, modify the input in place. Default: False.Notes
- Input:
(N, C, L)— batch of 1-D feature maps. - Output:
(N, C, L)— same shape; zeroed channels are uniformly zero along the entireLdimension.
The mask is sampled along the (N, C) axes only, then broadcast
over L. The forward pass delegates to the same engine kernel
as Dropout2d.
Dropout : Element-wise dropout. Dropout2d : Channel-wise dropout for 4-D (spatial) inputs. Dropout3d : Channel-wise dropout for 5-D (volumetric) inputs.
Examples
Channel-wise dropout on a batch of 1-D feature maps:
>>> import lucid, lucid.nn as nn
>>> drop1d = nn.Dropout1d(p=0.2)
>>> drop1d.train()
>>> x = lucid.ones(2, 8, 16) # (N=2, C=8, L=16)
>>> y = drop1d(x)
>>> y.shape
(2, 8, 16)
>>> # Each of the 8 channels is either all-zero or all-scaled
Verify pass-through in eval mode:
>>> drop1d.eval()
>>> y_eval = drop1d(lucid.ones(2, 8, 16))
>>> float(y_eval.sum()) == 256.0
TrueMethods (3)
__init__
→None__init__(p: float = 0.5, inplace: bool = False)Initialise the Dropout1d 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.