Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

load_lua TypeError: unhashable type: 'list' #37

Open
jtscs opened this issue Jun 23, 2018 · 3 comments
Open

load_lua TypeError: unhashable type: 'list' #37

jtscs opened this issue Jun 23, 2018 · 3 comments

Comments

@jtscs
Copy link

jtscs commented Jun 23, 2018

Hi,
I'm fairly new to nns and mainly trying to convert torch to caffe. Since torch2caffe and th2caffe frameworks bothg had issues I thought going from torch to pytorch and than via mmdnn to caffe.

When I tried the script I get the error:
TypeError: unhashable type: 'list'
Backtrace starts with line 315 and then 259 in the python script (which is the load_lua call) and then goes somewhere in the python package.
Last line is anaconda2/lib/python2.7/site_packages/torch/utils/serialization/read_lua_file.py, line 573 in read_table table[k] = v
Googeling the error, I found this NVIDIA/FastPhotoStyle#21
but adding long_size = 8 with a comma to load_lua did not change anything. Maybe I did it wrong.

I work on a virtual machine without any graphics support and thus whithout cuda. Version Ubuntu 16.04., Python 2.7. First I tried pip and then conda, I think both led to the same issue. Backtrace goes into anaconda2 directory.
conda list | grep torch returns
pytorch-cpu 0.4.0 py27_cpu_1 pytorch
torchvision-cpu 0.2.1 py27_1 pytorchpip
pip list | grep torch
torch 0.4.0
torchvision 0.2.1

Since it is not my model I am not sure if all layers of it are supported. Or am I still missig dependencies?
Thanks in advance for any help

@LancherJOJO
Copy link

LancherJOJO commented Jul 17, 2018

I got the same error. Have you solved it ?


I find the reason of this problem !!!!
Reason:
The function "load_lua" can load .t7 file where the data in the file must be keep a certain structure. Otherwise, the data may be in the mess.
For example, the structure may be in the form "str——value". But if your data of .t7 file are in the form of "str value value", the error will occur. The next k will be type of "value" instead of "str".
Solution:
You can add code " if type(k)==list: k=tuple(k) " in front of the code "table[k]=v ".
This problem is solved ,but other error maybe occur.....

@jtscs
Copy link
Author

jtscs commented Jul 18, 2018

So far I could not really solve the issue. I tried to work around the solution by using pytorch load_lua to load model and torch.save to save the model (which is supposed to be bad practice). Problem is I can not save a state_dict model which means I can not convert the pth file in mmdnn.
I tried your fix but it caused another error:
anaconda2/lib/python2.7/site-packages/torch/utils/serialization/read_lua_file.py", line 599, in read
"corrupted.".format(typeidx))
torch.utils.serialization.read_lua_file.T7ReaderException: unknown type id 9. The file may be corrupted.

@LancherJOJO
Copy link

I have abandoned this method to transform the model, which is not suitable for all models. Maybe there is a structure in your model that can not be identified by this method, so it does not work. I'm trying to write torch scripts to get data from the model, and then rebuild it myself. Maybe you can try it too. Good luck!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants