Sierkinhane / CRNN_Chinese_Characters_Rec

(CRNN) Chinese Characters Recognition.
1.82k stars 538 forks source link

python test.py error #18

Closed nothingeasy closed 5 years ago

nothingeasy commented 6 years ago

当我尝试运行这份代码时,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 commented 6 years ago

https://github.com/Sierkinhane/crnn_chinese_characters_rec/issues/14 可以参考这个解决(原因是你的字典和我训练好的字典不匹配)

nothingeasy commented 6 years ago

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