Skip to content
fn

dropout2d

→Tensor
dropout2d(input: Tensor, p: float = 0.5, training: bool = True, inplace: bool = False)

Implementing kernel

C++ engine symbols that back this Python API.

Channel-wise dropout for 2-D (spatial) feature maps.

Drops entire 2-D feature maps of an (N,C,H,W)(N, C, H, W) tensor with probability p and rescales the survivors by 1/(1−p)1/(1-p). This is the dropout variant of choice for convolutional networks (Tompson et al. 2015 "SpatialDropout"): adjacent pixels within a feature map are spatially correlated, so elementwise dropout removes very little information. Channel-wise masking forces independence between feature maps instead.

Parameters

inputTensor
Input tensor of shape (N,C,H,W)(N, C, H, W).
pfloat= 0.5
Channel-drop probability in [0,1][0, 1] (default 0.5).
trainingbool= True
When False, identity (default True).
inplacebool= False
If True, zero the dropped feature maps of input itself and return input (default False).

Returns

Tensor

Same shape and dtype as input.

Notes

For each batch element nn and channel cc, draw mn,c∼Bernoulli(1−p)m_{n,c} \sim \mathrm{Bernoulli}(1 - p) and broadcast over the spatial dimensions:

yn,c,h,w=mn,c1−p⋅xn,c,h,w.y_{n, c, h, w} = \frac{m_{n, c}}{1 - p} \cdot x_{n, c, h, w}.

Examples

>>> import lucid
>>> from lucid.nn.functional import dropout2d
>>> x = lucid.ones((2, 8, 4, 4))
>>> y = dropout2d(x, p=0.5, training=True)

Used by 2