mindspore.ops.Dropout2D

View Source On Gitee
class mindspore.ops.Dropout2D(keep_prob=0.5)[source]

During training, randomly zeroes some channels of the input tensor with probability \(1-keep\_prob\) from a Bernoulli distribution(For a 4-dimensional tensor with a shape of \((N, C, H, W)\), the channel feature map refers to a 2-dimensional feature map with the shape of \((H, W)\)).

Dropout2D can improve the independence between channel feature maps.

Note

The keep probability \(keep\_prob\) is equal to \(1 - p\) in mindspore.ops.dropout2d().

Parameters

keep_prob (float, optional) – The keep probability of a channel, between 0 and 1, e.g. keep_prob = 0.8, means dropping out 20% of channels. Default: 0.5 .

Inputs:
  • x (Tensor) - A 4-D tensor with shape \((N, C, H, W)\), where N is the batch size, C is the number of channels, H is the feature height, and W is the feature width.

Outputs:
  • output (Tensor) - With the same shape and data type as x.

  • mask (Tensor) - With the same shape as x and the data type is bool.

Raises
  • TypeError – If x is not a Tensor.

  • TypeError – If the data type of keep_prob is not float.

  • ValueError – If keep_prob is out of the range [0.0, 1.0].

  • ValueError – If x shape is not 4D.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> import numpy as np
>>> from mindspore import Tensor, ops
>>> dropout = ops.Dropout2D(keep_prob=0.5)
>>> x = Tensor(np.ones([2, 1, 2, 3]), mindspore.float32)
>>> output, mask = dropout(x)
>>> print(output.shape)
(2, 1, 2, 3)