Holmeyoung / crnn-pytorch

Pytorch implementation of CRNN (CNN + RNN + CTCLoss) for all language OCR.
MIT License
378 stars 105 forks source link

Problem about ctc_loss variable input_length while training #62

Closed 3a532028 closed 4 years ago

3a532028 commented 4 years ago

First,thank you for the code you provide. I try to use your code to train for recognizing licence plate. The char include alphabet ="""ABCDEFGHJKLMNPQRSTUVWXYZ0123456789-""" Sometimes the amount of plate number will be 7 or 8.

So I train with your code but got this Error , how do I fix? please~~~ 若方便的話,中文回覆也可以~謝謝您

Traceback (most recent call last):
  File "train.py", line 254, in <module>
    cost = train(crnn, criterion, optimizer, train_iter)
  File "train.py", line 242, in train
    cost = criterion(preds, text, preds_size, length) / batch_size
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 550,in __call__
    result = self.forward(*input, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/loss.py", line 1311, in forward
    self.zero_infinity)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/functional.py", line 2052, inctc_loss
    zero_infinity)
RuntimeError: Expected tensor to have size at least 12 at dimension 1, but got size 8for argument #2 'targets' (while checking arguments for ctc_loss_gpu)
3a532028 commented 4 years ago

I have solved the problem by editing "encode" function in util.py. Just remove the ".jpg" in filename. So that works! Still thank you BTW.