Comments (18)
Thanks @paffell for the trick.
For those of you who don't want to modify PyTorch's source code, you can do the following in your code just before loading the model:
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)
This is for the run_placesCNN_unified.py
example. For run_placesCNN_basic.py
, replace the model_file
in the last line with model_weight
.
Note that your pickle
namespace will be polluted after this operation. A better idea would be to copy the module first and modify the methods of this copy.
from places365.
I solved it with a small change in torch code in serialization.py lines 376-377 by adding the encoding there:
_sys_info = pickle_module.load(f,encoding='latin1')
unpickler = pickle_module.Unpickler(f,encoding='latin1')
I know it is not the cleanest solution, but it works :) To make it cleaner, it should be at least wrapped it by Try - Catch. But I do use Torch for this purpose only
from places365.
Indeed, it is the pickle library in python which cannot correctly load the CNN model trained in python2.7 into python3.6. Please let me know if there is some good solution for that.
from places365.
I solved in the same way as paffel did, and it works pretty well.
from places365.
No idea. maybe you could try useGPU = 1. Model is cached using python2.7.
from places365.
i met the same problem! Did you solve it?
from places365.
i use python 3.6, i think the version may be the key!
from places365.
yep, i just use virtualenv to create a pure environment for python2.7 and all is ok.
thank you for your reply! this is an excellent work!
from places365.
Thanks @soravux for cleaning the solution. I started to use it as well :)
from places365.
Thanks @soravux, it works for me too.
from places365.
@soravux Thanks so much!!! it's work for me
from places365.
from places365.
UnpicklingError: invalid load key, '\x5c'.
Getting the same error.Can anyone help?
from places365.
_pickle.UnpicklingError: invalid load key, '\x04'.
Getting the same error. Tried Soravux's method, still report error.
from places365.
I solved in the same way as paffel did, and it works pretty well.
will you please mention the line numbers and the file name. Thanks.
from places365.
from places365.
The hack suggested in this issue, i.e., the following line:
pickle.Unpickler = partial(pickle.Unpickler, encoding="latin1")
completely breaks toch.load
since version 1.11 because in that version, PyTorch subclasses pickle.Unpickler
but after this, pickle.Unpickler
is a function and not a type which leads to the following error:
[...]
File "lib/python3.9/site-packages/torch/serialization.py", line 820, in _legacy_load
class UnpicklerWrapper(pickle_module.Unpickler): # type: ignore[name-defined]
TypeError: the first argument must be callable
To load models saved in Python2, since PyTorch 1.1.0 (released May 2019), do
torch.load(...., encoding='latin1')
from places365.
from places365.
Related Issues (20)
- AlexNet PyTorch weights are corrupt
- Image Dimensions
- Cannot download the dataset now HOT 12
- Where is the 'W_sceneattribute_wideresnet18.npy' file? HOT 2
- 504 Gateway Time-out response from dataset download server
- Attribute prediction weights for Hybrid1365 models HOT 1
- running in windows cmd platform HOT 1
- About confusions in run_placesCNN_unified.py
- The domain http://places2.csail.mit.edu is down HOT 4
- Demo website is down HOT 1
- Is there anywhere to obtain the dataset anymore? HOT 6
- model can not download HOT 1
- Generate Heatmap for categories that is not the top1
- wideresnet18_places365.pth.tar file not found HOT 6
- Resnet50_places365.t7 Issues!
- vgg16_hybrid1365 model output shape error
- Where can I download the Places365 Dataset? HOT 1
- python run_placesCNN_basic.py stopped working - cant download model tar file HOT 1
- Link to Pretrained model weights are broken. HOT 1
- The labels in the website and the labels in the dataset are different.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from places365.