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

出现一个RuntimeError #14

Closed
yangjx54 opened this issue Oct 17, 2018 · 17 comments
Closed

出现一个RuntimeError #14

yangjx54 opened this issue Oct 17, 2018 · 17 comments

Comments

@yangjx54
Copy link

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.
打扰了,刚接触这方面的问题,跑程序的时候遇到了这个问题。请问有什么解决办法吗?

@haneSier
Copy link

字典不对,alphabet 不要改,用原来的

@yangjx54
Copy link
Author

你好,我什么东西都没动,然后出现了这个问题。是不是和我的环境之类的有关系?

@Sierkinhane
Copy link
Owner

这个错误和 alphabet.py 里面定义的alphabet字典有关,你可以重新下载这个文件或是复制里面的alphabet

@yangjx54
Copy link
Author

非常感谢,我再尝试一下,谢谢了。

@yangjx54
Copy link
Author

你好,我还有个问题想要请教一下。之前因为用ubuntu14,遇到各种问题,所以就想按照你的环境重新配置。然后在安装pytorch时候,因为官网的指令安装的是0.1.12,在安装CTC会遇到问题,所以我就直接在官网下载了torch-0.4.0-cp35-cp35m-linux_x86_64.whl进行安装。但是在运行程序的时候会遇到
import torchvision.transforms as transforms
ImportError: No module named 'torchvision'
这个问题。
如果我要是直接用conda install torchvision的话,会告诉我:
The following NEW packages will be INSTALLED:

pytorch:     0.1.12-py35cuda8.0cudnn6.0_1
torchvision: 0.1.8-py35_0   

这会不会影响我已经装好的pytorch和CTC,还是有其他的办法单独装torchvision?查了好多资料,都是直接一起装的。

@haneSier
Copy link

看你的提示信息是会安装的0.12的pytorch 和torchvision. 你可以试试用pip安装torchvision,一般16.04的bug少些,可以试试

@yangjx54
Copy link
Author

非常感谢,现在已经可以使用了。我还有点问题,我找了一些需要识别的图像,主要是数字和字母,字体稍大,就类似于车牌号码的样子,然后我调整了大小,但是识别的效果很差,基本上没有一个字识别出来的,我是不是需要针对这种图重新进行训练才可以使用?

@haneSier
Copy link

如果你想模型很robust的话,就用一个很多样的训练集

@yangjx54
Copy link
Author

你好,作为小白,真的非常感谢你提供的帮助,然后我现在是用了一部分自己的图做了个数据集,但是比较小,测试和训练一共加起来就400多张,然后做迁移,现在loss是0.5885,accuray是0.8375。我如果想要提高准确率的话是不是需要使用更多的数据进行训练才可以?

@haneSier
Copy link

是的,数量更多更多样化的数据

@OKhyc
Copy link

OKhyc commented Dec 27, 2018

@yangjx54 你好,你的数据是怎么练的,我现在也有一些特定文字的图片,我应该如何训练。 你练完后需要把项目原来的数据集删除,换成自己训练的数据吗。

@haneSier
Copy link

如果你的数据和我数据有很大差别,就直接迁移学习到你的数据集,

@lixin-cv
Copy link

我遇到了同样的问题,使用alphabet.py原始文件文件会出现
SyntaxError: Non-ASCII character '\xe6' in file /home/py/lx/CRNN/crnn_chinese_characters_rec-master/alphabets.py
错误,应该是编码错误,我在文件头加上了# -- coding: UTF-8 --,就报以下错误:
loading pretrained model from trained_models/mixed_second_finetune_acc97p7.pth
Traceback (most recent call last):
File "test.py", line 67, in
model.load_state_dict(torch.load(crnn_model_path))
File "/home/py/.local/lib/python2.7/site-packages/torch/nn/modules/module.py", line 769, 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 with shape torch.Size([6736]) from checkpoint, the shape in current model is torch.Size([19997]).
size mismatch for rnn.1.embedding.weight: copying a param with shape torch.Size([6736, 512]) from checkpoint, the shape in current model is torch.Size([19997, 512]).
求助,谢谢!

@Sierkinhane
Copy link
Owner

字典不匹配,原始的是6736个字符,你给定的是19997个字符

@lixin-cv
Copy link

我是直接copy你的alphabet.py文件,有什么地方需要修改么?

@aabbcc1234mxd
Copy link

同想知道,这个预训练pth的文件如何初始化,比如原来使用5500多字符,现在我自己新增了100多字符,请问如何在原来的基础上修改文件进行训练?

@aabbcc1234mxd
Copy link

搞了半天实在没有什么解决方法,我是直接将alphabet中5000多字符里面不常用的(比如一些极其生僻字,还有日语平假名。。)没啥必要的,直接就替换了,现在跑起来效果挺好,第一次CUDA_ERROR把batchsize设成了1,结果训练了十万张还没啥用,注意一下就好了

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

6 participants