https://pytorch.org/docs/stable/generated/torch.nn.Dropout.html?highlight=dropout#torch.nn.Dropout
- Dropout–(仅应用于模型的训练过程–model.train())
1、dropout会将tensor元素以概率p置零;
2、非零的元素会变为原来的1/(1-p)倍数。
如下例所示:
import torch
input = torch.randn(4, 5)
dropout = torch.nn.Dropout(0.3)
result = dropout(input)
print(input)
print(result)
'''
input:
tensor([[ 1.4809, 0.1342, 0.9399, 0.0523, -1.3157],
[-0.2424, 0.5072, 2.8424, 0.5662, 1.6336],
[-0.8658, 0.1746, -0.2445, 2.0440, 0.7870],
[ 0.3833, 0.7818, -1.1788, 0.7310, -0.3212]])
--------------------------------------------------------
result:
tensor([[ 2.1156, 0.0000, 1.3428, 0.0747, -0.0000],
[-0.0000, 0.0000, 4.0605, 0.0000, 0.0000],
[-1.2369, 0.2494, -0.3492, 0.0000, 1.1242],
[ 0.0000, 1.1169, -1.6840, 1.0443, -0.4588]])
如:
1.4809 * (1/(1-0.3)) = 2.1156
-0.8658* (1/(1-0.3)) = -1.2369
'''