Skip to content

Commit

Permalink
Add new option -l for combine_tessdata to list the network string
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Weil <[email protected]>
  • Loading branch information
stweil committed Jan 15, 2021
1 parent 970eba7 commit 3195c8f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
3 changes: 3 additions & 0 deletions doc/combine_tessdata.1.asc
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ OPTIONS
*-e* '.traineddata' 'FILE'...:
Extracts the specified components from the .traineddata file
*-l* '.traineddata' 'FILE'...:
List the network information.
*-o* '.traineddata' 'FILE'...:
Overwrites the specified components of the .traineddata file
with those provided on the command line.
Expand Down
6 changes: 6 additions & 0 deletions src/lstm/lstmrecognizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ class TESS_API LSTMRecognizer {
return learning_rate_;
}
}

// Return the network string.
const char* GetNetwork() const {
return network_str_.c_str();
}

// Multiplies the all the learning rate(s) by the given factor.
void ScaleLearningRate(double factor) {
ASSERT_HOST(network_ != nullptr && network_->type() == NT_SERIES);
Expand Down
23 changes: 21 additions & 2 deletions src/training/combine_tessdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "tessdatamanager.h"

#include <cerrno>
#include <iostream> // std::cout

using namespace tesseract;

Expand Down Expand Up @@ -174,6 +175,21 @@ int main(int argc, char **argv) {
} else if (argc == 3 && strcmp(argv[1], "-d") == 0) {
// Initialize TessdataManager with the data in the given traineddata file.
tm.Init(argv[2]);
} else if (argc == 3 && strcmp(argv[1], "-l") == 0) {
if (!tm.Init(argv[2])) {
tprintf("Failed to read %s\n", argv[2]);
return EXIT_FAILURE;
}
tesseract::TFile fp;
if (tm.GetComponent(tesseract::TESSDATA_LSTM, &fp)) {
tesseract::LSTMRecognizer recognizer;
if (!recognizer.DeSerialize(&tm, &fp)) {
tprintf("Failed to deserialize LSTM in %s!\n", argv[2]);
return EXIT_FAILURE;
}
std::cout << recognizer.GetNetwork() << '\n';
}
return EXIT_SUCCESS;
} else {
printf("Usage for combining tessdata components:\n"
" %s language_data_path_prefix\n"
Expand All @@ -188,10 +204,13 @@ int main(int argc, char **argv) {
argv[0], argv[0]);
printf("Usage for unpacking all tessdata components:\n"
" %s -u traineddata_file output_path_prefix\n"
" (e.g. %s -u eng.traineddata tmp/eng.)\n", argv[0], argv[0]);
" (e.g. %s -u eng.traineddata tmp/eng.)\n\n", argv[0], argv[0]);
printf("Usage for listing the network information\n"
" %s -l traineddata_file\n"
" (e.g. %s -l eng.traineddata)\n\n", argv[0], argv[0]);
printf(
"Usage for listing directory of components:\n"
" %s -d traineddata_file\n",
" %s -d traineddata_file\n\n",
argv[0]);
printf(
"Usage for compacting LSTM component to int:\n"
Expand Down

0 comments on commit 3195c8f

Please sign in to comment.