mindspore.ops.DropoutDoMask

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

Applies dropout mask on the input tensor.

Take the mask output of DropoutGenMask as input, and apply dropout on the input.

Droupt means tha neural network units are temporarily dropped from the network according to a certain probability during the deep learning network training. Generally, The effect of Dropout is the same as that of DropoutGenMask and DropoutDoMask. The DropoutGenMask generates a mask shape that is specified based on the input. Next, The DropoutDoMask is a mask generated using DropoutGenMask. The input tensor is randomly set to zero based on the probability p.

Inputs:
  • input_x (Tensor) - The input tensor. The data type should be float32, float16 or int32

  • mask (Tensor) - The mask to be applied on input_x, which is the output of DropoutGenMask. And the shape of input_x must be the same as the value of DropoutGenMask’s input shape. If input wrong mask, the output of DropoutDoMask are unpredictable.

  • keep_prob (Union[Tensor, float]) - The keep rate, greater than 0 and less equal than 1, e.g. keep_prob = 0.9, means dropping out 10% of input units. The value of keep_prob is the same as the input keep_prob of the operator DropoutGenMask.

Outputs:

Tensor, the value that applied dropout on.

Raises
  • TypeError – If input_x, mask or keep_prob is not a Tensor.

  • TypeError – If keep_prob is not a float.

  • ValueError – If value of keep_prob is not same as DropoutGenMaks.

Supported Platforms:

Ascend

Examples

>>> input_x = Tensor(np.ones([2, 2, 3]), mindspore.float32)
>>> shape = (2, 2, 3)
>>> keep_prob = Tensor(0.5, mindspore.float32)
>>> dropout_gen_mask = ops.DropoutGenMask()
>>> dropout_do_mask = ops.DropoutDoMask()
>>> mask = dropout_gen_mask(shape, keep_prob)
>>> output = dropout_do_mask(input_x, mask, keep_prob)
>>> print(output.shape)
(2, 2, 3)