lstmtraining: Handle missing traineddata with error message (fix issue #1075)

Signed-off-by: Stefan Weil <sw@weilnetz.de>
This commit is contained in:
Stefan Weil 2021-10-30 12:26:10 +02:00
parent 2a66694754
commit 68017dbf2a
2 changed files with 10 additions and 4 deletions

View File

@ -112,7 +112,10 @@ int main(int argc, char **argv) {
tesseract::LSTMTrainer trainer(FLAGS_model_output.c_str(), checkpoint_file.c_str(),
FLAGS_debug_interval,
static_cast<int64_t>(FLAGS_max_image_MB) * 1048576);
trainer.InitCharSet(FLAGS_traineddata.c_str());
if (!trainer.InitCharSet(FLAGS_traineddata.c_str())) {
tprintf("Error, failed to read %s\n", FLAGS_traineddata.c_str());
return EXIT_FAILURE;
}
// Reading something from an existing model doesn't require many flags,
// so do it now and exit.

View File

@ -95,9 +95,12 @@ public:
// Initializes the character set encode/decode mechanism directly from a
// previously setup traineddata containing dawgs, UNICHARSET and
// UnicharCompress. Note: Call before InitNetwork!
void InitCharSet(const std::string &traineddata_path) {
ASSERT_HOST(mgr_.Init(traineddata_path.c_str()));
InitCharSet();
bool InitCharSet(const std::string &traineddata_path) {
bool success = mgr_.Init(traineddata_path.c_str());
if (success) {
InitCharSet();
}
return success;
}
void InitCharSet(const TessdataManager &mgr) {
mgr_ = mgr;