File to load trained model

when i load trained mode(trained in GPU,python3.6) in another computer(only cpu,python 2.7),but the error show as follow.And i add the '#!/usr/bin/env python# --coding:utf-8 --‘at the top.’

so why the bug at line 388 when i load the trained model?
thinks
Traceback (most recent call last):
File “hahaha.py”, line 388, in
pre_train_model_mask = torch.load(model_dir_mask,map_location=lambda storage, loc: storage)
File “/usr/local/lib/python2.7/dist-packages/torch/serialization.py”, line 303, in load
return _load(f, map_location, pickle_module)
File “/usr/local/lib/python2.7/dist-packages/torch/serialization.py”, line 469, in _load
result = unpickler.load()
File “/home/chxx/predict/Model_Xception1.py”, line 47
SyntaxError: Non-ASCII character ‘\xe7’ in file /home/chxx/predict/Model_Xception1.py on line 47, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

As it says, it has to do with encoding not PyTorch. Try adding below line (or other alternatives as mentioned in the given link):

# -*- coding: utf-8 -*-
1 Like