class paddle.nn. Dropout2D ( p=0.5, data_format='NCHW', name=None ) [source]

Randomly zero out entire channels (in the batched input 4d tensor with the shape NCHW , a channel is a 2D feature map with the shape HW). Each channel will be zeroed out independently on every forward call with probability p using samples from a Bernoulli distribution. Dropout2D will help promote independence between feature maps as described in the paper: Efficient Object Localization Using Convolutional Networks

See paddle.nn.functional.dropout2d for more details.

In dygraph mode, please use eval() to switch to evaluation mode, where dropout is disabled.

  • p (float, optional) – Probability of setting units to zero. Default: 0.5

  • data_format (str, optional) – Specify the data format of the input, and the data format of the output will be consistent with that of the input. An optional string from NCHW or NHWC. The default is NCHW. When it is NCHW, the data is stored in the order of: [batch_size, input_channels, input_height, input_width].

  • name (str, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.

  • input: 4-D tensor.

  • output: 4-D tensor, the same shape as input.


import paddle
import numpy as np

x = np.random.random(size=(2, 3, 4, 5)).astype('float32')
x = paddle.to_tensor(x)
m = paddle.nn.Dropout2D(p=0.5)
y_train = m(x)
m.eval()  # switch the model to test phase
y_test = m(x)
forward ( input )


Defines the computation performed at every call. Should be overridden by all subclasses.

  • *inputs (tuple) – unpacked tuple arguments

  • **kwargs (dict) – unpacked dict arguments

extra_repr ( )


Extra representation of this layer, you can have custom implementation of your own layer.