在 pytorch 多GPU训练下,存储 整个模型 ( 而不是model.state_dict() )后再调用模型可能会遇到下面的情况:

AttributeError: ‘DataParallel’ object has no attribute ‘xxxx’

解决的方法是:

model = torch.load('path/to/model')
#添加语句部分
if isinstance(model,torch.nn.DataParallel):
		model = model.module

#下面就可以正常使用了
model.eval()
...
...
...
Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐