diff --git "a/code/2021_spring/\345\234\272\346\231\257\350\257\206\345\210\253/\351\273\204\347\216\256\347\220\2522019302110409/convert_python36.py" "b/code/2021_spring/\345\234\272\346\231\257\350\257\206\345\210\253/\351\273\204\347\216\256\347\220\2522019302110409/convert_python36.py" new file mode 100644 index 0000000000000000000000000000000000000000..f2b926c9b5e5eacb734d5a3456ade059a569cb77 --- /dev/null +++ "b/code/2021_spring/\345\234\272\346\231\257\350\257\206\345\210\253/\351\273\204\347\216\256\347\220\2522019302110409/convert_python36.py" @@ -0,0 +1,20 @@ +import torch +from torch.autograd import Variable as V +import torchvision.models as models +from torchvision import transforms as trn +from torch.nn import functional as F + + +archs = ['resnet50','densenet161','alexnet'] +for arch in archs: + model_file = 'whole_%s_places365.pth.tar' % arch + save_file = 'whole_%s_places365_python36.pth.tar' % arch + + from functools import partial + import pickle + pickle.load = partial(pickle.load, encoding="latin1") + pickle.Unpickler = partial(pickle.Unpickler, encoding="latin1") + model = torch.load(model_file, map_location=lambda storage, loc: storage, pickle_module=pickle) + torch.save(model, save_file) + print('converting %s -> %s'%(model_file, save_file)) +