fn

dropout2d

Tensor
dropout2d(x: Tensor, p: float = 0.5, training: bool = True)
source

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/(1p)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

xTensor
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).

Returns

Tensor

Same shape and dtype as x.

Notes

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

yn,c,h,w=mn,c1pxn,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)