Dropout2D¶
- 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 dropout2d for more details.
In dygraph mode, please use
eval()
to switch to evaluation mode, where dropout is disabled.- Parameters
-
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. When it is NCHW, the data is stored in the order of: [batch_size, input_channels, input_height, input_width]. Default: NCHW.
name (str, optional) – Name for the operation, Default: None. For more information, please refer to Name.
- Shape:
-
input: 4-D tensor.
output: 4-D tensor, the same shape as input.
Examples
>>> import paddle >>> paddle.seed(100) >>> x = paddle.rand([2, 2, 1, 3], dtype="float32") >>> print(x) Tensor(shape=[2, 2, 1, 3], dtype=float32, place=Place(cpu), stop_gradient=True, [[[[0.55355281, 0.20714243, 0.01162981]], [[0.51577556, 0.36369765, 0.26091650]]], [[[0.18905126, 0.56219709, 0.00808361]], [[0.78120756, 0.32112977, 0.90572405]]]]) >>> m = paddle.nn.Dropout2D(p=0.5) >>> y_train = m(x) >>> print(y_train) Tensor(shape=[2, 2, 1, 3], dtype=float32, place=Place(cpu), stop_gradient=True, [[[[1.10710561, 0.41428486, 0.02325963]], [[1.03155112, 0.72739530, 0.52183300]]], [[[0. , 0. , 0. ]], [[0. , 0. , 0. ]]]]) >>> m.eval() # switch the model to test phase >>> y_test = m(x) >>> print(y_test) Tensor(shape=[2, 2, 1, 3], dtype=float32, place=Place(cpu), stop_gradient=True, [[[[0.55355281, 0.20714243, 0.01162981]], [[0.51577556, 0.36369765, 0.26091650]]], [[[0.18905126, 0.56219709, 0.00808361]], [[0.78120756, 0.32112977, 0.90572405]]]])
-
forward
(
input
)
forward¶
-
Defines the computation performed at every call. Should be overridden by all subclasses.
- Parameters
-
*inputs (tuple) – unpacked tuple arguments
**kwargs (dict) – unpacked dict arguments
-
extra_repr
(
)
extra_repr¶
-
Extra representation of this layer, you can have custom implementation of your own layer.