
- 加载模型出现 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')
- TypeError: ‘IncompatibleKeys’ object is not callable
- 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'))
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)