mindspore.ops.dropout

View Source On Gitee
mindspore.ops.dropout(input, p=0.5, training=True, seed=None)[source]

During training, randomly zeroes some of the elements of the input tensor with probability p from a Bernoulli distribution. It plays the role of reducing neuron correlation and avoid overfitting. And the return will be multiplied by \(\frac{1}{1-p}\) during training. During the reasoning, this operation returns the same Tensor as the x.

Warning

The Ascend backend does not support the reproducibility of random numbers, so the seed parameter has no effect.

Parameters
  • input (Tensor) – The input Tensor of shape \((*, N)\), with data type of float16, float32 or float64.

  • p (float, optional) – The dropping rate, between 0 and 1, e.g. p = 0.1, means dropping out 10% of input units. Default: 0.5 .

  • training (bool) – Apply dropout if is True. Default: True.

  • seed (int, optional) – Seed is used as entropy source for Random number engines generating pseudo-random numbers. Default: None , which will be treated as 0 .

Returns

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

Raises
  • TypeError – If p is not a float.

  • TypeError – If dtype of input is not float16, float32 or float64.

  • TypeError – If input is not a Tensor.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> from mindspore import Tensor, ops
>>> input = Tensor(((20, 16), (50, 50)), mindspore.float32)
>>> output = ops.dropout(input, p=0.5)
>>> print(output.shape)
(2, 2)