-
Notifications
You must be signed in to change notification settings - Fork 9.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Run LSTM recognition in multiple threads #4275
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -169,8 +169,11 @@ bool Tesseract::init_tesseract_lang_data(const std::string &arg0, | |
tessedit_ocr_engine_mode == OEM_TESSERACT_LSTM_COMBINED) { | ||
#endif // ndef DISABLED_LEGACY_ENGINE | ||
if (mgr->IsComponentAvailable(TESSDATA_LSTM)) { | ||
lstm_recognizer_ = new LSTMRecognizer(language_data_path_prefix.c_str()); | ||
ASSERT_HOST(lstm_recognizer_->Load(this->params(), lstm_use_matrix ? language : "", mgr)); | ||
for (int i = 0; i < lstm_num_threads; ++i) { | ||
lstm_recognizers_.push_back(new LSTMRecognizer(language_data_path_prefix.c_str())); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fine for me. Upd.: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was just following the existing design pattern of tesseract of using |
||
lstm_recognizers_.back()->Load(this->params(), lstm_use_matrix ? language : "", mgr); | ||
} | ||
lstm_recognizer_ = lstm_recognizers_[0]; | ||
} else { | ||
tprintf("Error: LSTM requested, but not present!! Loading tesseract.\n"); | ||
tessedit_ocr_engine_mode.set_value(OEM_TESSERACT_ONLY); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about static thread pool here?
If code is called multiple times, how is std::async performance compared to static thread pool?
Considering async will create a new thread each time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question.
As
stweil
has clarified in his latest comment, this multiple lstm threads is not meant for mass production. This feature is probably meant for consumer-end devices running a single page OCR once in a while, but with least possible latency. In such cases thread creation/deletion is not a big overhead. But if we really come across use-cases where thread creation/deletion overhead becomes significant, we could look at replacing this with a thread pool at that point.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default case (lstm_num_threads == 1) must not create a new thread.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, the default case (lstm_num_threads == 1) does not create a new thread. As you see, the loop starts with
i = 1
, and hence does not execute whenlstm_num_threads == 1
.