githubharald / SimpleHTR

Handwritten Text Recognition (HTR) system implemented with TensorFlow.
https://towardsdatascience.com/2326a3487cd5
MIT License
1.99k stars 894 forks source link

Setting a fixed output length #94

Closed mkuehn94 closed 3 years ago

mkuehn94 commented 3 years ago

Is it possible to set some constraints to the output of the decoder, for example if I know that all words are excactly 10 characters long. I know this is not an issue with the code but any help would be greatly appreciated, I was looking inside the tensorflow api and ctc paper without any luck

githubharald commented 3 years ago

you can try "constrained decoding". You will have to implement it yourself, TF does not provide this. The idea is the following: use beam search, which creates a list of text candidates at each iteration step. Limit the allowed text candidates (i.e. all texts with length 10 and all their prefixes), so that beam search is only allowed to follow beams which contain text the way you want it.

You can have a look at word beam search(code + paper), which is a slightly different use-case but which you could use as a starting point for further experiments.