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

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Chris_zhangrx/article/details/86619834

在 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()
...
...
...

猜你喜欢

转载自blog.csdn.net/Chris_zhangrx/article/details/86619834
今日推荐