【发布时间】:2020-09-20 23:04:05
【问题描述】:
我正在尝试使 BLSTM 的输出具有确定性,经过调查,似乎我的 dropout 层创建了不确定的 dropout 掩码,因此我正在研究如何修复pytorch 中的随机种子。我找到了this page 和其他建议,尽管我将所有内容都放入了代码中,但没有帮助。这是我的代码:
import sys
import random
import datetime as dt
import numpy as np
import torch
torch.manual_seed(42)
torch.cuda.manual_seed(42)
np.random.seed(42)
random.seed(42)
torch.backends.cudnn.deterministic = True
ex = torch.ones(10)
torch.nn.functional.dropout(ex, p=0.5, training=True)
# Out[29]: tensor([0., 0., 2., 0., 0., 0., 0., 0., 2., 2.])
torch.nn.functional.dropout(ex, p=0.5, training=True)
# Out[30]: tensor([0., 2., 0., 2., 2., 0., 0., 2., 2., 2.])
请帮助我从 dropout 中获得相同输入的确定性输出
【问题讨论】:
标签: python pytorch random-seed dropout