tesseract  4.00.00dev
lstmeval.cpp
Go to the documentation of this file.
1 // File: lstmeval.cpp
3 // Description: Evaluation program for LSTM-based networks.
4 // Author: Ray Smith
5 // Created: Wed Nov 23 12:20:06 PST 2016
6 //
7 // (C) Copyright 2016, Google Inc.
8 // Licensed under the Apache License, Version 2.0 (the "License");
9 // you may not use this file except in compliance with the License.
10 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
12 // Unless required by applicable law or agreed to in writing, software
13 // distributed under the License is distributed on an "AS IS" BASIS,
14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 // See the License for the specific language governing permissions and
16 // limitations under the License.
18 
19 #ifndef USE_STD_NAMESPACE
20 #include "base/commandlineflags.h"
21 #endif
22 #include "commontraining.h"
23 #include "genericvector.h"
24 #include "lstmtester.h"
25 #include "strngs.h"
26 #include "tprintf.h"
27 
28 STRING_PARAM_FLAG(model, "", "Name of model file (training or recognition)");
29 STRING_PARAM_FLAG(eval_listfile, "",
30  "File listing sample files in lstmf training format.");
31 INT_PARAM_FLAG(max_image_MB, 2000, "Max memory to use for images.");
32 
33 int main(int argc, char **argv) {
34  ParseArguments(&argc, &argv);
35  if (FLAGS_model.empty()) {
36  tprintf("Must provide a --model!\n");
37  return 1;
38  }
39  if (FLAGS_eval_listfile.empty()) {
40  tprintf("Must provide a --eval_listfile!\n");
41  return 1;
42  }
43  GenericVector<char> model_data;
44  if (!tesseract::LoadDataFromFile(FLAGS_model.c_str(), &model_data)) {
45  tprintf("Failed to load model from: %s\n", FLAGS_eval_listfile.c_str());
46  return 1;
47  }
48  tesseract::LSTMTester tester(static_cast<inT64>(FLAGS_max_image_MB) *
49  1048576);
50  if (!tester.LoadAllEvalData(FLAGS_eval_listfile.c_str())) {
51  tprintf("Failed to load eval data from: %s\n", FLAGS_eval_listfile.c_str());
52  return 1;
53  }
54  double errs = 0.0;
55  STRING result = tester.RunEvalSync(0, &errs, model_data, 0);
56  tprintf("%s\n", result.string());
57  return 0;
58 } /* main */
#define tprintf(...)
Definition: tprintf.h:31
const char * string() const
Definition: strngs.cpp:198
void ParseArguments(int *argc, char ***argv)
Definition: strngs.h:45
bool LoadDataFromFile(const char *filename, GenericVector< char > *data)
int main(int argc, char **argv)
Definition: lstmeval.cpp:33
STRING RunEvalSync(int iteration, const double *training_errors, const GenericVector< char > &model_data, int training_stage)
Definition: lstmtester.cpp:82
bool LoadAllEvalData(const STRING &filenames_file)
Definition: lstmtester.cpp:30
INT_PARAM_FLAG(max_image_MB, 2000, "Max memory to use for images.")
STRING_PARAM_FLAG(model, "", "Name of model file (training or recognition)")