Holmeyoung / crnn-pytorch

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

How do we add more classes to the pretrained model #5

Closed mariembenslama closed 5 years ago

mariembenslama commented 5 years ago

I wanted to use your pretrained model to add to it some alphabets.

But I get the error of size mistach because the number of classes is not the same.

How am I supposed to change in the last layer? I want to add more classes to the pretrained model (state).

Holmeyoung commented 5 years ago

Hi, you can load partial weight of the net. And whatโ€™s the performance of your net?!!!, the net you trained a few days agao!

mariembenslama commented 5 years ago

Sadly I restarted my training again because I had some personnal issues... I started again today and it's going well for starter ^_^ Epoch 4/300: test loss = 0.018, accuracy = 0.69, so I guess it fine for a debut, right?

A question: when training it on text with a fixed length = 10, is it capable after that to recognize longer text > 10 (I mean later on when using the pre-trained model to recognize any text as input - length < 40 for example)?

Holmeyoung commented 5 years ago

We use ctc-loss which supports variable length! The image length of pre-trained model doesnโ€™t decide something like the net structure. The rnn layer will take the image sequence length = 26 as input. No longer shorter or longer than 26, it will be the same finally, yes, itโ€™s 26. Just like the training process output

- a - - b b b - - - - - - c - - - - - - d d - - - -

it abcdd (just example)

In other words, although you labels are all 6 , it can be used to predict 10, and also it can be used as the pre-trained model of labels length 10

mariembenslama commented 5 years ago

Understood! :) thank you very much. And by the way, my training reached 84% accuracy and 0.0012 loss on 17 epochs ๐Ÿ˜ , still growing up!

๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰

Holmeyoung commented 5 years ago

Wow! I know you can do it!

mariembenslama commented 5 years ago

I really can't thank you enough! I hope you do well in everything in your life from now on! ๐Ÿ˜๐Ÿ˜๐Ÿ’ชโค๏ธ