【发布时间】:2020-09-11 18:31:38
【问题描述】:
当我完成语义分割的训练任务(pytorch 0.4.1 GPU CUDA9.0),并成功推断模型(pytorch 0.4.1),但是当我将我的 pytorch 版本切换到 1.1.0 时,我结果略有不同。有什么问题???
【问题讨论】:
-
我在切换pytroch版本前后没有调整任何代码
-
请举个例子
标签: pytorch
当我完成语义分割的训练任务(pytorch 0.4.1 GPU CUDA9.0),并成功推断模型(pytorch 0.4.1),但是当我将我的 pytorch 版本切换到 1.1.0 时,我结果略有不同。有什么问题???
【问题讨论】:
标签: pytorch
我只使用一个 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))))```
【讨论】: