Pytorch 0.4.1和1.1.0之间有区别吗

时间:2020-05-25 06:35:25

标签: pytorch

当我完成语义分段的训练任务(pytorch 0.4.1 GPU CUDA9.0)并成功推断出模型(pytorch 0.4.1)时,但是当我将pytorch版本切换到1.1.0时,我结果略有不同。有什么问题吗?

1 个答案:

答案 0 :(得分:0)

我发现仅使用一层Conv2d层就存在差异。在pytorch0.4.1中,nn.Conv2d的输出和公式的输出始终相同。但是有时在pytorch1.1中它们是不同的。我很困惑!!!!

import torch.nn as nn
torch.set_printoptions(precision=64)
input_t = torch.randn((3,3))
input_t = input_t.unsqueeze(0).unsqueeze(0).float()
class minimodel(nn.Module):
    def __init__(self):
        super(minimodel, self).__init__()
        self.conv = nn.Conv2d(1, 1, kernel_size=3)
    def forward(self, x):
        x = self.conv(x)
        return x
demo_model = minimodel()
weight = torch.load("model.ckpt")
demo_model.load_state_dict(torch.load("model.ckpt"))
demo_model.eval()
output_t = demo_model(input_t)
# torch.save(demo_model.state_dict(),"model.ckpt")
print("#####output of nn.Conv2d#####")
print(output_t)
Kernel_W = weight['conv.weight']

print("####output of formula######")
print(torch.add(weight['conv.bias'],torch.sum(torch.mul(Kernel_W, input_t))))```