Parallelizing RecogAllWordsPassN

15 views
Skip to first unread message

ste...@scanbot.io

unread,
Dec 4, 2018, 5:26:58 AM12/4/18
to tesseract-ocr
Hi all,

I'm looking to get better parallelism out of Tesseract in LSTM engine mode. I attempted to parallelize the loop over all words in RecogAllWordsPassN. To do this first I created N instances of LSTMRecognizer, all loaded with the same data. Then, I split the words in the page into N word sets, so that each set has approximately the same number of ROW's. Finally I parallelized the loop on N cores by processing each word set with the corresponding LSTMRecognizer instance. The speed-up I got was about 1.8x for N=2, which is very nice, but the code itself is not stable. As far as I can tell, the PAGE_RES_IT structure provides mutable access to the page data and I didn't synchronize mutations. This lead to crashes due to (I'm guessing here) inconsistencies in the PAGE_RES.

Looking at PAGE_RES_IT, it looks like a rabbit hole of data interdependencies and I'm not sure if just slapping a scoped_lock in ReplaceCurrentWord and the rest of the mutators is enough to make multithreaded operation in RecogAllWordsPassN safe.

How would you advise me to continue? Do you think that mutexing PAGE_RES is enough to provide crash-free word-level parallelism? Or maybe I should duplicate the PAGE_RES structure, with each duplicate containing only part of the rows, process each PAGE_RES object in parallel and then somehow merge the results?

Much obliged,
Stefan Dragnev.
Reply all
Reply to author
Forward
0 new messages