【问题标题】:Is there a difference between Pytorch 0.4.1 and 1.1.0Pytorch 0.4.1 和 1.1.0 有区别吗
【发布时间】:2020-09-11 18:31:38
【问题描述】:

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

【问题讨论】:

  • 我在切换pytroch版本前后没有调整任何代码
  • 请举个例子

标签: pytorch


【解决方案1】:

我只使用一个 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))))```

【讨论】:

  • 我发现无论pytorch的版本是什么都存在差异???!!!,另外,我尝试在CPU和GPU上进行计算,两者都存在......
  • 您是否找到了解决此问题的方法,或者您是否设法找到了使结果相同的方法?
猜你喜欢
  • 2022-01-24
  • 2021-07-02
  • 2019-07-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多