Pytorch测试模型问题记录

Pytorch测试模型问题记录,第1张

Pytorch测试模型问题记录
  1. 加载模型出现 RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available()
    因为模型是在GPU上训练的,然后我在CPU上加载就会报错,可以尝试下面方法:
checkpoint = torch.load("xxx/model.pth")  改为
checkpoint = torch.load("xxx/model.pth",map_location='cpu')
  1. TypeError: ‘IncompatibleKeys’ object is not callable
  2. pytorch加载模型报错TypeError: ‘collections.OrderedDict‘ object is not callable
    以上两种报错的时候,只需要按照下面的这种写法即可
model = getattr(models, opt.model)().eval()
model.load_state_dict(torch.load("xxx/resnet34.pth",map_location='cpu'))

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/883421.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-14
下一篇2022-05-14

发表评论

登录后才能评论

评论列表(0条)

    保存