为什么Pytorch Dropout层会影响所有的值,而不仅仅是设置为零的值?

4 人关注

Pytorch的dropout层改变了没有被设置为零的值。使用Pytorch的文档例子:( source ):

import torch
import torch.nn  as nn
m = nn.Dropout(p=0.5)
input = torch.ones(5, 5)
print(input)
tensor([[1., 1., 1., 1., 1.],
        [1., 1., 1., 1., 1.],
        [1., 1., 1., 1., 1.],
        [1., 1., 1., 1., 1.],
        [1., 1., 1., 1., 1.]])

然后我把它通过一个dropout层。

output = m(input)
print(output)
tensor([[0., 0., 2., 2., 0.],
        [2., 0., 2., 0., 0.],
        [0., 0., 0., 0., 2.],
        [2., 2., 2., 2., 2.],
        [2., 0., 0., 0., 2.]])

没有设置为零的数值现在是2。为什么?

python
pytorch
tensor
dropout
Nicolas Gervais
Nicolas Gervais
发布于 2019-11-23
1 个回答
Miguel
Miguel
发布于 2019-11-23
已采纳
0 人赞同