python2的torch model如何在python3中载入

python2的torch model如何在python3中载入

载入https://github.com/ox-vgg/vgg_face2 vgg官方模型时出了问题
该版本为Python2但我想在python3环境下跑
在查了源码和官方代码和一些网友提供的答案后,使用如下代码成功载入

import pickle
import io
from functools import partial
MainModel = imp.load_source('MainModel', 'resnet50_ft_pytorch.py')
pickle.load = partial(pickle.load, encoding="latin1")
pickle.Unpickler = partial(pickle.Unpickler, encoding="latin1")
param_dict = torch.load(model_path)

你可能感兴趣的:(pytorch)