Holmeyoung / crnn-pytorch

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

Train problem #60

Open susanin1970 opened 4 years ago

susanin1970 commented 4 years ago

Hi! Firstly, thank you for the code :) I use your CRNN model for recognition numbers of ISO-containers (ISO 6346) And I have the problem

I have a small dataset of ISO-numbers (100 train samples and 50 test samples). They look like this: TGHU6548874_79

I chose various parameters (nepoch, valInterval, saveInterval, etc. and trained model didn't create in the directory after save interval (I use default directory -- "expr") When I set saveInterval = 1 and valInterval = 1 and try to train, many trained models create in the directory Changing batch size doesn't help I use Google Colaboratory for training

What might be the problem? Maybe I need more train data? Or choose the right parameters for training? Thank you on advance for answer :)

P.S. Sorry for my bad English P.S.S. Can your model recognize vertically oriented text like this? CAIU7894238_161

Holmeyoung commented 4 years ago
if __name__ == "__main__":
    for epoch in range(params.nepoch):
        train_iter = iter(train_loader)
        i = 0
        while i < len(train_loader):
            cost = train(crnn, criterion, optimizer, train_iter)
            loss_avg.add(cost)
            i += 1

            if i % params.displayInterval == 0:
                print('[%d/%d][%d/%d] Loss: %f' %
                      (epoch, params.nepoch, i, len(train_loader), loss_avg.val()))
                loss_avg.reset()

            if i % params.valInterval == 0:
                val(crnn, criterion)

            # do checkpointing
            if i % params.saveInterval == 0:
                torch.save(crnn.state_dict(), '{0}/netCRNN_{1}_{2}.pth'.format(params.expr_dir, epoch, i))

if you have 100 images and you batch_size if 8, so you will have i from 1 to 100//8+1=13. So, if you set saveInterval bigger than 13, it will never equal to 0. P.S. It can't recognize vertically oriented text like that.