mindspore.ops.Dropout2D

class mindspore.ops.Dropout2D(*args, **kwargs)[source]

During training, randomly zeroes some of the channels of the input tensor with probability 1-keep_prob from a Bernoulli distribution.

Parameters

keep_prob (float) – 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:
  • input (Tensor) - A 4-D tensor with shape \((N, C, H, W)\).

Outputs:
  • output (Tensor) - with the same shape and data type as the input tensor.

  • mask (Tensor[bool]) - with the same shape as the input tensor.

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

  • ValueError – If keep_prob is out of the range [0.0, 1.0]; or if the dim of input is not 4-D.

Supported Platforms:

Ascend

Examples

>>> dropout = ops.Dropout2D(keep_prob=0.5)
>>> x = Tensor(np.random.randn(2, 1, 2, 3), mindspore.float32)
>>> output, mask = dropout(x)
>>> print(output)
[[[[0. 0. 0.]
   [0. 0. 0.]]]
 [[[0.88 -2.98 -0.01]
   [2.16 -0.34 1.57]]]]
>>> print(mask)
[[[[False False False]
   [False False False]]]
 [[[True True True]
   [True True True]]]]