From 68017dbf2a584730adc6c562fd6afc722c957fcb Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Sat, 30 Oct 2021 12:26:10 +0200 Subject: [PATCH] lstmtraining: Handle missing traineddata with error message (fix issue #1075) Signed-off-by: Stefan Weil --- src/training/lstmtraining.cpp | 5 ++++- src/training/unicharset/lstmtrainer.h | 9 ++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/training/lstmtraining.cpp b/src/training/lstmtraining.cpp index fd365423..8852a5ce 100644 --- a/src/training/lstmtraining.cpp +++ b/src/training/lstmtraining.cpp @@ -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(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. diff --git a/src/training/unicharset/lstmtrainer.h b/src/training/unicharset/lstmtrainer.h index cdebf989..292b2ef5 100644 --- a/src/training/unicharset/lstmtrainer.h +++ b/src/training/unicharset/lstmtrainer.h @@ -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;