megengine.functional.nn.dropout#

dropout(inp, drop_prob, training=True)[source]#

Returns a new tensor where each of the elements are randomly set to zero with probability P = drop_prob. Optionally rescale the output tensor if training is True.

Parameters:
  • inp (Tensor) – input tensor.

  • drop_prob (float) – probability to drop (set to zero) a single element.

  • training (bool) – the default behavior of dropout during training is to rescale the output, then it can be replaced by an Identity during inference. Default: True

Return type:

Tensor

Returns:

the ouput tensor

Examples

>>> import numpy as np
>>> data = Tensor(np.ones(10000000, dtype=np.float32))
>>> out = F.nn.dropout(data, 1.0 / 3.0, training=True)
>>> assert not out.numpy().all()
>>> out = F.nn.dropout(data, 1.0 / 3.0, training=False)
>>> assert out.numpy().all()
>>> out.numpy()
array([1., 1., 1., ..., 1., 1., 1.], dtype=float32)