From baa250f40480610869a7f4fca545b407bf8e385d Mon Sep 17 00:00:00 2001 From: 199******99 <9200608+doglikegodness@user.noreply.gitee.com> Date: Sat, 10 Jul 2021 09:51:01 +0000 Subject: [PATCH] =?UTF-8?q?add=20code/2021=5Fspring/=E5=9C=BA=E6=99=AF?= =?UTF-8?q?=E8=AF=86=E5=88=AB/=E9=BB=84=E7=8E=AE=E7=90=AA2019302110409/con?= =?UTF-8?q?vert=5Fpython36.py.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../convert_python36.py" | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 "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" 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 0000000..f2b926c --- /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)) + -- Gitee