我试图通过在训练和推理(蒙特卡罗辍学)过程中保持辍学概率来接近贝叶斯模型,以获得该模型的认知不确定性.
有没有一种方法可以修复重复性的所有随机性来源(随机种子),但保持辍学的随机性?
# Set random seed for reproducibility
seed = 123
torch.manual_seed(seed)
random.seed(seed)
np.random.seed(seed)
# Training and Inference phase (with dropout)
dropout_mask = torch.bernoulli(torch.full_like(input, 1 - self.dropout))
skip = self.skip0(input * dropout_mask / (1 - self.dropout))
for i in range(self.layers):
residual = x
filter = self.filter_convs[i](x)
filter = torch.tanh(filter)
gate = self.gate_convs[i](x)
gate = torch.sigmoid(gate)
x = filter * gate
dropout_mask = torch.bernoulli(torch.full_like(x, 1 - self.dropout))
x = x * dropout_mask / (1 - self.dropout)
s = x
s = self.skip_convs[i](s)
skip = s + skip
if self.gcn_true:
x = self.gconv1[i](x, adp) + self.gconv2[i](x, adp.transpose(1, 0))
else:
x = self.residual_convs[i](x)
x = x + residual[:, :, :, -x.size(3):]
if idx is None:
x = self.norm[i](x, self.idx)
else:
x = self.norm[i](x, idx)
skip = self.skipE(x) + skip
x = F.relu(skip)
x = F.relu(self.end_conv_1(x))
x = self.end_conv_2(x)
return x
上面的代码每次都会产生相同的结果,这不是我想要做的.