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

python test.py error #18

Closed
nothingeasy opened this issue Oct 23, 2018 · 2 comments
Closed

python test.py error #18

nothingeasy opened this issue Oct 23, 2018 · 2 comments

Comments

@nothingeasy
Copy link

当我尝试运行这份代码时,test.py 有以下报错信息,疑惑?
我添加了map_location='cpu' 是这个原因吗?
model.load_state_dict(torch.load(crnn_model_path,map_location='cpu'))

报错信息:

python test.py ****
loading pretrained model from trained_models/mixed_second_finetune_acc97p7.pth
Traceback (most recent call last):
File "test.py", line 64, in
**model.load_state_dict(torch.load(crnn_model_path,map_location='cpu')) **
File "/home/seven/anaconda3/envs/chinese_ocr/lib/python2.7/site-packages/torch/nn/modules/module.py", line 719, in load_state_dict
self.class.name, "\n\t".join(error_msgs)))
RuntimeError: Error(s) in loading state_dict for CRNN:
size mismatch for rnn.1.embedding.bias: copying a param of torch.Size([19997]) from checkpoint, where the shape is torch.Size([6736]) in current model.
size mismatch for rnn.1.embedding.weight: copying a param of torch.Size([19997, 512]) from checkpoint, where the shape is torch.Size([6736, 512]) in current model.

@Sierkinhane
Copy link
Owner

#14 可以参考这个解决(原因是你的字典和我训练好的字典不匹配)

@nothingeasy
Copy link
Author

谢谢~ 我改动python3.6后就可用了
但是我还是发现一个问题,我用Python2.7跑时会提示非法字符,无奈我添加了#-- coding:utf-8 --在文件头部,从而导致一楼的问题,切换到py3.6后就正常了

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