pytorch加载模型时出现:‘Generator’ object has no attribute ‘copy’错误
pytorch保存网络的方式
在pytorch保存网络模型时保存整个网络模型,使用如下方法
#保存整个网络
torch.save(net, save_path)
在pytorch保存网络模型时保存网络模型的参数,使用如下方法
#保存网络的参数
torch.save(net.state_dict(), save_path)
错误的理由
保存了整个网络模型,但是根据保存的网络模型参数加载,如下
net = Generator()
pthfile ="./sat2mapGen_v1.3.pth"
net.load_state_dict(torch.load(pthfile,map_location='cpu'))
net.eval
正确的方式
pthfile ="./sat2mapGen_v1.3.pth"
net = torch.load(pthfile,map_location='cuda')
net.eval
版权声明:本文为博主莎蒲蒲和我原创文章,版权归属原作者,如果侵权,请联系我们删除!
原文链接:https://blog.csdn.net/qq_44758471/article/details/123085275