对dropout的一点理解

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
'''

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值