Holmeyoung / crnn-pytorch

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

how to recognize blank, recognize English and Chinese in one model #48

Open ghost opened 4 years ago

ghost commented 4 years ago

Firstly, you codes are great. I trained with SynthText90k dataset and achieved very good performance on English words.

there are several questions. hopefully you can give me a hand. Thank you very much. thanks for your time.

  1. How to recognize blank in one sentence? for example,I want to recognize "I love python" there is blank between I and love. how to handle this problem? just add blank in alphabet? like this? and prepare for the training data alphabet = """0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ """

  2. Can we recognize English and Chinese in one model? if we want to recognize English and Chinese in one model, how to do? just make alphabet contain all English and Chinese characters? just like this? alphabet = """0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ是不我一有大在人了中到資..."""

  3. if we want to recognize very long sentence? do you think it would be better to train with very long sentences or we can just train with short sentence? because your current model only support text length less than 26. so have to modify the network if I want to support training with long sentence.

Holmeyoung commented 4 years ago

Hi,

  1. these are two different things, recognize sentence and segment sentences. Just add blank in the labels is not recommended.

  2. just make alphabet contain all English and Chinese characters, like what you say.

  3. Calculate the last lstm T length. The longer you resize image width to be, the longer you can train with. One location for one word.

ghost commented 4 years ago

Thank you so much for your help.

ghost commented 4 years ago

How to recognize blank between two English words? for my current model, if I input one English sentence then the output will concatenate all the English words together. for example: inputed image:

36

recognized result:

A------l-ll-t-h--e--r-e-c--o--g-n-i-tiio---n--a-c-cc--ur-a--c-i-e-s---o--n--t-h---e => Alltherecognitionaccuraciesonthe

So how to recognize the blank between two English words?

Holmeyoung commented 4 years ago

Try to give the label

all#the#recognition#accuracies#on#the

replace all the blanks with #, and put the word # in alphabets.py

So, when there is blank, the net will output #, and you can replace # with blank, you will get normal sentences.

You can try as this, but i am not sure about it.

ghost commented 4 years ago

thanks for your reply. maybe blank itself can also be considered as a character. So currently I decide not to replace blank with #. I decide to add the blank character itself to alphabet and train with English sentences. wait for my results. thank you so much.

ghost commented 4 years ago

@Holmeyoung it is not necessary to replace blank with #. just view blank itself as one character and add blank to the alphabet. then prepare for English sentences as training data. alphabet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'. -,"

my training images: image image

the following are training progress: image

you can find that it works. finally, I'm very grateful to you for your responses to all my questions. Thank you again.

ducbluee commented 4 years ago

@cvchongci Hi, I am also having problems with the space between words in English. could you please share your model ??? thanks!!!

ghost commented 4 years ago

@ducbluee Hi, I used very limited synthetic data to train the model. so the model does not work well on real-world images. you can follow the way I handle blank.