megengine.functional.nn.dropout¶
- dropout(inp, drop_prob, training=True)[源代码]¶
返回一个新张量,其中每个元素按概率 P =
drop_prob
随机被设置为零。可以选择是否重新缩放输出张量。- 参数
- 返回类型
- 返回
the ouput tensor
实际案例
import numpy as np from megengine import tensor import megengine.functional as F # test training mode data = tensor(np.ones(10000000, dtype=np.float32)) out = F.nn.dropout(data, 1.0 / 3.0, training=True) assert not out.numpy().all() # test eval mode out = F.nn.dropout(data, 1.0 / 3.0, training=False) assert out.numpy().all()
输出:
[1.5 1.5 0. 1.5 1.5 1.5 1.5 1.5 1.5 1.5]