【发布时间】:2020-03-19 02:25:31
【问题描述】:
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