MobilePose-Pi icon indicating copy to clipboard operation
MobilePose-Pi copied to clipboard

TypeError: load() got an unexpected keyword argument 'encoding'

Open csyang6052 opened this issue 5 years ago • 0 comments

Dear Sirs, I am able to install Pytorch and all other required libs. My setup - Pi 3, model B, python2.7, OpenCV 3.4. TypeError occurred, however, as shown below -

pi@raspberrypi:~/MobilePose-Pi/mobilepose-pi $ python eval.py --model mobilenet 0 Loading testing dataset, wait... 100%|██████████| 1/1 [00:10<00:00, 10.58s/it] Traceback (most recent call last): File "eval.py", line 158, in eval_coco(full_name, os.path.join(PATH_PREFIX, 'result-gt-json.txt'), os.path.join(PATH_PREFIX, 'result-pred-json.txt')) File "eval.py", line 103, in eval_coco net = torch.load(net_path, map_location=lambda storage, loc: storage, pickle_module=pickle) File "/usr/local/lib/python2.7/dist-packages/torch/serialization.py", line 385, in load return _load(f, map_location, pickle_module, **pickle_load_args) File "/usr/local/lib/python2.7/dist-packages/torch/serialization.py", line 562, in _load magic_number = pickle_module.load(f, **pickle_load_args) TypeError: load() got an unexpected keyword argument 'encoding'

I noticed, in ~/MobilePose-Pi/mobilepose-pi/models directory, there is a '.t7' extension for three different models, mobilenetv2_224x224-robust.t7, resnet18_227x227-robust.t7, and shufflenetv2_224x224.t7, which are for Torch not for PyTorch. Is the TypeError due to this? Ref - https://github.com/mdtux89/amr-eager/issues/4

After digging in, I noticed line 99, 100 in ~/MobilePose-Pi/mobilepose-pi/eval.py - pickle.load = partial(pickle.load, encoding="latin1") # code added to interface to python3 pickle.Unpickler = partial(pickle.Unpickler, encoding="latin1") # code added to interface to python3 These codes are for python3? Since I used python2.7 for execution eval.py, are these codes the reason for TypeError? After commenting out line 99, 100, another error occur - AttributeError: 'Conv2d' object has no attribute 'padding_mode' (Details shown below)

pi@raspberrypi:~/MobilePose-Pi/mobilepose-pi $ python eval.py --model mobilenet 0 Loading testing dataset, wait... 100%|██████████| 1/1 [00:09<00:00, 9.28s/it] ==> write./results/mobilenet/result-gt-json.txt 0%| | 0/1 [00:00<?, ?it/s] Traceback (most recent call last): File "eval.py", line 158, in eval_coco(full_name, os.path.join(PATH_PREFIX, 'result-gt-json.txt'), os.path.join(PATH_PREFIX, 'result-pred-json.txt')) File "eval.py", line 138, in eval_coco output = net(Variable(sample_data['image'],volatile=True)) File "/usr/local/lib/python2.7/dist-packages/torch/nn/modules/module.py", line 491, in call result = self.forward(*input, **kwargs) File "/home/pi/MobilePose-Pi/mobilepose-pi/mobilenetv2.py", line 108, in forward x = self.features(x) File "/usr/local/lib/python2.7/dist-packages/torch/nn/modules/module.py", line 491, in call result = self.forward(*input, **kwargs) File "/usr/local/lib/python2.7/dist-packages/torch/nn/modules/container.py", line 97, in forward input = module(input) File "/usr/local/lib/python2.7/dist-packages/torch/nn/modules/module.py", line 491, in call result = self.forward(*input, **kwargs) File "/usr/local/lib/python2.7/dist-packages/torch/nn/modules/container.py", line 97, in forward input = module(input) File "/usr/local/lib/python2.7/dist-packages/torch/nn/modules/module.py", line 491, in call result = self.forward(*input, **kwargs) File "/usr/local/lib/python2.7/dist-packages/torch/nn/modules/conv.py", line 332, in forward if self.padding_mode == 'circular': File "/usr/local/lib/python2.7/dist-packages/torch/nn/modules/module.py", line 537, in getattr type(self).name, name)) AttributeError: 'Conv2d' object has no attribute 'padding_mode'

For executing eval.py on Pi 3 using python2.7, are following codes correct for execution? - # cpu mode pickle.load = partial(pickle.load, encoding="latin1") # code added to interface to python3 pickle.Unpickler = partial(pickle.Unpickler, encoding="latin1") # code added to interface to python3 # model = torch.load(model_file, map_location=lambda storage, loc: storage, pickle_module=pickle) net = Net() net = torch.load(net_path, map_location=lambda storage, loc: storage, pickle_module=pickle) If not, how to modify?

csyang6052 avatar Mar 22 '19 01:03 csyang6052