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

inconsistent tensor size, expected tensor [1 x 736 x 8 x 16] and src [1 x 1248 x 8 x 16] to have the same number of elements #5

Open
younglululu opened this issue Nov 11, 2018 · 2 comments

Comments

@younglululu
Copy link

I am making prediction using the trained models. I used the following command:

python prediction_emb.py 100 param/dia_all_epo20_dim24_conv10/dia_all_epo20_dim24_conv10_filled.pt 10 data/mod.txt

And here is the error I encoutered which is reproducible in both python 2.7 and python 3.7, pytorch version 0.4.1

While copying the parameter named digit_capsules.route_weights, whose dimensions in the model are torch.Size([1, 736, 8, 16]) and whose dimensions in the checkpoint are torch.Size([1, 1248, 8, 16]), ...
Traceback (most recent call last):
File "prediction_emb.py", line 78, in
obse,pred1=pred_from_model(conv1,conv1,round1model,RTtest,15)
File "prediction_emb.py", line 17, in pred_from_model
model.load_state_dict(torch.load(param_path))
File "/home/yanglu/anaconda2/envs/dl_env/lib/python2.7/site-packages/torch/nn/modules/module.py", line 360, in load_state_dict
own_state[name].copy_(param)
RuntimeError: inconsistent tensor size, expected tensor [1 x 736 x 8 x 16] and src [1 x 1248 x 8 x 16] to have the same number of elements, but got 94208 and 159744 elements respectively at /opt/conda/conda-bld/pytorch_1503966894950/work/torch/lib/TH/generic/THTensorCopy.c:86

@horsepurve
Copy link
Owner

horsepurve commented Nov 11, 2018

Hi, because here "dia" and "mod" are two different data sets with different maximum peptide lengths (66 vs. 50), please simply change line #16 in config.py to be:

max_length = 66

And while making prediction using another trained model, just change this value to be the max peptide length in that data set (e.g. 50 in "mod" data).

Thank you.

@younglululu
Copy link
Author

younglululu commented Nov 11, 2018 via email

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