tesseract  4.1.0
lstmrecognizer.cpp
Go to the documentation of this file.
1 // File: lstmrecognizer.cpp
3 // Description: Top-level line recognizer class for LSTM-based networks.
4 // Author: Ray Smith
5 // Created: Thu May 02 10:59:06 PST 2013
6 //
7 // (C) Copyright 2013, 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 // Include automatically generated configuration file if running autoconf.
20 #ifdef HAVE_CONFIG_H
21 # include "config_auto.h"
22 #endif
23 
24 #include "lstmrecognizer.h"
25 
26 #include "allheaders.h"
27 #include "callcpp.h"
28 #include "dict.h"
29 #include "genericheap.h"
30 #include "helpers.h"
31 #include "imagedata.h"
32 #include "input.h"
33 #include "lstm.h"
34 #include "normalis.h"
35 #include "pageres.h"
36 #include "ratngs.h"
37 #include "recodebeam.h"
38 #include "scrollview.h"
39 #include "statistc.h"
40 #include "tprintf.h"
41 
42 namespace tesseract {
43 
44 // Default ratio between dict and non-dict words.
45 const double kDictRatio = 2.25;
46 // Default certainty offset to give the dictionary a chance.
47 const double kCertOffset = -0.085;
48 
50  : network_(nullptr),
51  training_flags_(0),
52  training_iteration_(0),
53  sample_iteration_(0),
54  null_char_(UNICHAR_BROKEN),
55  learning_rate_(0.0f),
56  momentum_(0.0f),
57  adam_beta_(0.0f),
58  dict_(nullptr),
59  search_(nullptr),
60  debug_win_(nullptr) {}
61 
63  delete network_;
64  delete dict_;
65  delete search_;
66 }
67 
68 // Loads a model from mgr, including the dictionary only if lang is not null.
69 bool LSTMRecognizer::Load(const ParamsVectors* params, const char* lang,
70  TessdataManager* mgr) {
71  TFile fp;
72  if (!mgr->GetComponent(TESSDATA_LSTM, &fp)) return false;
73  if (!DeSerialize(mgr, &fp)) return false;
74  if (lang == nullptr) return true;
75  // Allow it to run without a dictionary.
76  LoadDictionary(params, lang, mgr);
77  return true;
78 }
79 
80 // Writes to the given file. Returns false in case of error.
81 bool LSTMRecognizer::Serialize(const TessdataManager* mgr, TFile* fp) const {
82  bool include_charsets = mgr == nullptr ||
85  if (!network_->Serialize(fp)) return false;
86  if (include_charsets && !GetUnicharset().save_to_file(fp)) return false;
87  if (!network_str_.Serialize(fp)) return false;
88  if (!fp->Serialize(&training_flags_)) return false;
89  if (!fp->Serialize(&training_iteration_)) return false;
90  if (!fp->Serialize(&sample_iteration_)) return false;
91  if (!fp->Serialize(&null_char_)) return false;
92  if (!fp->Serialize(&adam_beta_)) return false;
93  if (!fp->Serialize(&learning_rate_)) return false;
94  if (!fp->Serialize(&momentum_)) return false;
95  if (include_charsets && IsRecoding() && !recoder_.Serialize(fp)) return false;
96  return true;
97 }
98 
99 // Reads from the given file. Returns false in case of error.
101  delete network_;
103  if (network_ == nullptr) return false;
104  bool include_charsets = mgr == nullptr ||
107  if (include_charsets && !ccutil_.unicharset.load_from_file(fp, false))
108  return false;
109  if (!network_str_.DeSerialize(fp)) return false;
110  if (!fp->DeSerialize(&training_flags_)) return false;
111  if (!fp->DeSerialize(&training_iteration_)) return false;
112  if (!fp->DeSerialize(&sample_iteration_)) return false;
113  if (!fp->DeSerialize(&null_char_)) return false;
114  if (!fp->DeSerialize(&adam_beta_)) return false;
115  if (!fp->DeSerialize(&learning_rate_)) return false;
116  if (!fp->DeSerialize(&momentum_)) return false;
117  if (include_charsets && !LoadRecoder(fp)) return false;
118  if (!include_charsets && !LoadCharsets(mgr)) return false;
121  return true;
122 }
123 
124 // Loads the charsets from mgr.
126  TFile fp;
127  if (!mgr->GetComponent(TESSDATA_LSTM_UNICHARSET, &fp)) return false;
128  if (!ccutil_.unicharset.load_from_file(&fp, false)) return false;
129  if (!mgr->GetComponent(TESSDATA_LSTM_RECODER, &fp)) return false;
130  if (!LoadRecoder(&fp)) return false;
131  return true;
132 }
133 
134 // Loads the Recoder.
136  if (IsRecoding()) {
137  if (!recoder_.DeSerialize(fp)) return false;
138  RecodedCharID code;
140  if (code(0) != UNICHAR_SPACE) {
141  tprintf("Space was garbled in recoding!!\n");
142  return false;
143  }
144  } else {
147  }
148  return true;
149 }
150 
151 // Loads the dictionary if possible from the traineddata file.
152 // Prints a warning message, and returns false but otherwise fails silently
153 // and continues to work without it if loading fails.
154 // Note that dictionary load is independent from DeSerialize, but dependent
155 // on the unicharset matching. This enables training to deserialize a model
156 // from checkpoint or restore without having to go back and reload the
157 // dictionary.
158 // Some parameters have to be passed in (from langdata/config/api via Tesseract)
160  const char* lang, TessdataManager* mgr) {
161  delete dict_;
162  dict_ = new Dict(&ccutil_);
163  dict_->user_words_file.ResetFrom(params);
164  dict_->user_words_suffix.ResetFrom(params);
165  dict_->user_patterns_file.ResetFrom(params);
166  dict_->user_patterns_suffix.ResetFrom(params);
168  dict_->LoadLSTM(lang, mgr);
169  if (dict_->FinishLoad()) return true; // Success.
170  tprintf("Failed to load any lstm-specific dictionaries for lang %s!!\n",
171  lang);
172  delete dict_;
173  dict_ = nullptr;
174  return false;
175 }
176 
177 // Recognizes the line image, contained within image_data, returning the
178 // ratings matrix and matching box_word for each WERD_RES in the output.
179 void LSTMRecognizer::RecognizeLine(const ImageData& image_data, bool invert,
180  bool debug, double worst_dict_cert,
181  const TBOX& line_box,
183  int lstm_choice_mode) {
184  NetworkIO outputs;
185  float scale_factor;
186  NetworkIO inputs;
187  if (!RecognizeLine(image_data, invert, debug, false, false, &scale_factor,
188  &inputs, &outputs))
189  return;
190  if (search_ == nullptr) {
191  search_ =
193  }
194  search_->Decode(outputs, kDictRatio, kCertOffset, worst_dict_cert,
195  &GetUnicharset(), lstm_choice_mode);
196  search_->ExtractBestPathAsWords(line_box, scale_factor, debug,
197  &GetUnicharset(), words, lstm_choice_mode);
198 }
199 
200 // Helper computes min and mean best results in the output.
201 void LSTMRecognizer::OutputStats(const NetworkIO& outputs, float* min_output,
202  float* mean_output, float* sd) {
203  const int kOutputScale = INT8_MAX;
204  STATS stats(0, kOutputScale + 1);
205  for (int t = 0; t < outputs.Width(); ++t) {
206  int best_label = outputs.BestLabel(t, nullptr);
207  if (best_label != null_char_) {
208  float best_output = outputs.f(t)[best_label];
209  stats.add(static_cast<int>(kOutputScale * best_output), 1);
210  }
211  }
212  // If the output is all nulls it could be that the photometric interpretation
213  // is wrong, so make it look bad, so the other way can win, even if not great.
214  if (stats.get_total() == 0) {
215  *min_output = 0.0f;
216  *mean_output = 0.0f;
217  *sd = 1.0f;
218  } else {
219  *min_output = static_cast<float>(stats.min_bucket()) / kOutputScale;
220  *mean_output = stats.mean() / kOutputScale;
221  *sd = stats.sd() / kOutputScale;
222  }
223 }
224 
225 // Recognizes the image_data, returning the labels,
226 // scores, and corresponding pairs of start, end x-coords in coords.
227 bool LSTMRecognizer::RecognizeLine(const ImageData& image_data, bool invert,
228  bool debug, bool re_invert, bool upside_down,
229  float* scale_factor, NetworkIO* inputs,
230  NetworkIO* outputs) {
231  // Maximum width of image to train on.
232  const int kMaxImageWidth = 2560;
233  // This ensures consistent recognition results.
234  SetRandomSeed();
235  int min_width = network_->XScaleFactor();
236  Pix* pix = Input::PrepareLSTMInputs(image_data, network_, min_width,
237  &randomizer_, scale_factor);
238  if (pix == nullptr) {
239  tprintf("Line cannot be recognized!!\n");
240  return false;
241  }
242  if (network_->IsTraining() && pixGetWidth(pix) > kMaxImageWidth) {
243  tprintf("Image too large to learn!! Size = %dx%d\n", pixGetWidth(pix),
244  pixGetHeight(pix));
245  pixDestroy(&pix);
246  return false;
247  }
248  if (upside_down) pixRotate180(pix, pix);
249  // Reduction factor from image to coords.
250  *scale_factor = min_width / *scale_factor;
251  inputs->set_int_mode(IsIntMode());
252  SetRandomSeed();
254  network_->Forward(debug, *inputs, nullptr, &scratch_space_, outputs);
255  // Check for auto inversion.
256  float pos_min, pos_mean, pos_sd;
257  OutputStats(*outputs, &pos_min, &pos_mean, &pos_sd);
258  if (invert && pos_min < 0.5) {
259  // Run again inverted and see if it is any better.
260  NetworkIO inv_inputs, inv_outputs;
261  inv_inputs.set_int_mode(IsIntMode());
262  SetRandomSeed();
263  pixInvert(pix, pix);
265  &inv_inputs);
266  network_->Forward(debug, inv_inputs, nullptr, &scratch_space_,
267  &inv_outputs);
268  float inv_min, inv_mean, inv_sd;
269  OutputStats(inv_outputs, &inv_min, &inv_mean, &inv_sd);
270  if (inv_min > pos_min && inv_mean > pos_mean && inv_sd < pos_sd) {
271  // Inverted did better. Use inverted data.
272  if (debug) {
273  tprintf("Inverting image: old min=%g, mean=%g, sd=%g, inv %g,%g,%g\n",
274  pos_min, pos_mean, pos_sd, inv_min, inv_mean, inv_sd);
275  }
276  *outputs = inv_outputs;
277  *inputs = inv_inputs;
278  } else if (re_invert) {
279  // Inverting was not an improvement, so undo and run again, so the
280  // outputs match the best forward result.
281  SetRandomSeed();
282  network_->Forward(debug, *inputs, nullptr, &scratch_space_, outputs);
283  }
284  }
285  pixDestroy(&pix);
286  if (debug) {
287  GenericVector<int> labels, coords;
288  LabelsFromOutputs(*outputs, &labels, &coords);
289  DisplayForward(*inputs, labels, coords, "LSTMForward", &debug_win_);
290  DebugActivationPath(*outputs, labels, coords);
291  }
292  return true;
293 }
294 
295 // Converts an array of labels to utf-8, whether or not the labels are
296 // augmented with character boundaries.
298  STRING result;
299  int end = 1;
300  for (int start = 0; start < labels.size(); start = end) {
301  if (labels[start] == null_char_) {
302  end = start + 1;
303  } else {
304  result += DecodeLabel(labels, start, &end, nullptr);
305  }
306  }
307  return result;
308 }
309 
310 // Displays the forward results in a window with the characters and
311 // boundaries as determined by the labels and label_coords.
313  const GenericVector<int>& labels,
314  const GenericVector<int>& label_coords,
315  const char* window_name,
316  ScrollView** window) {
317 #ifndef GRAPHICS_DISABLED // do nothing if there's no graphics
318  Pix* input_pix = inputs.ToPix();
319  Network::ClearWindow(false, window_name, pixGetWidth(input_pix),
320  pixGetHeight(input_pix), window);
321  int line_height = Network::DisplayImage(input_pix, *window);
322  DisplayLSTMOutput(labels, label_coords, line_height, *window);
323 #endif // GRAPHICS_DISABLED
324 }
325 
326 // Displays the labels and cuts at the corresponding xcoords.
327 // Size of labels should match xcoords.
329  const GenericVector<int>& xcoords,
330  int height, ScrollView* window) {
331 #ifndef GRAPHICS_DISABLED // do nothing if there's no graphics
332  int x_scale = network_->XScaleFactor();
333  window->TextAttributes("Arial", height / 4, false, false, false);
334  int end = 1;
335  for (int start = 0; start < labels.size(); start = end) {
336  int xpos = xcoords[start] * x_scale;
337  if (labels[start] == null_char_) {
338  end = start + 1;
339  window->Pen(ScrollView::RED);
340  } else {
341  window->Pen(ScrollView::GREEN);
342  const char* str = DecodeLabel(labels, start, &end, nullptr);
343  if (*str == '\\') str = "\\\\";
344  xpos = xcoords[(start + end) / 2] * x_scale;
345  window->Text(xpos, height, str);
346  }
347  window->Line(xpos, 0, xpos, height * 3 / 2);
348  }
349  window->Update();
350 #endif // GRAPHICS_DISABLED
351 }
352 
353 // Prints debug output detailing the activation path that is implied by the
354 // label_coords.
356  const GenericVector<int>& labels,
357  const GenericVector<int>& xcoords) {
358  if (xcoords[0] > 0)
359  DebugActivationRange(outputs, "<null>", null_char_, 0, xcoords[0]);
360  int end = 1;
361  for (int start = 0; start < labels.size(); start = end) {
362  if (labels[start] == null_char_) {
363  end = start + 1;
364  DebugActivationRange(outputs, "<null>", null_char_, xcoords[start],
365  xcoords[end]);
366  continue;
367  } else {
368  int decoded;
369  const char* label = DecodeLabel(labels, start, &end, &decoded);
370  DebugActivationRange(outputs, label, labels[start], xcoords[start],
371  xcoords[start + 1]);
372  for (int i = start + 1; i < end; ++i) {
373  DebugActivationRange(outputs, DecodeSingleLabel(labels[i]), labels[i],
374  xcoords[i], xcoords[i + 1]);
375  }
376  }
377  }
378 }
379 
380 // Prints debug output detailing activations and 2nd choice over a range
381 // of positions.
383  const char* label, int best_choice,
384  int x_start, int x_end) {
385  tprintf("%s=%d On [%d, %d), scores=", label, best_choice, x_start, x_end);
386  double max_score = 0.0;
387  double mean_score = 0.0;
388  const int width = x_end - x_start;
389  for (int x = x_start; x < x_end; ++x) {
390  const float* line = outputs.f(x);
391  const double score = line[best_choice] * 100.0;
392  if (score > max_score) max_score = score;
393  mean_score += score / width;
394  int best_c = 0;
395  double best_score = 0.0;
396  for (int c = 0; c < outputs.NumFeatures(); ++c) {
397  if (c != best_choice && line[c] > best_score) {
398  best_c = c;
399  best_score = line[c];
400  }
401  }
402  tprintf(" %.3g(%s=%d=%.3g)", score, DecodeSingleLabel(best_c), best_c,
403  best_score * 100.0);
404  }
405  tprintf(", Mean=%g, max=%g\n", mean_score, max_score);
406 }
407 
408 // Helper returns true if the null_char is the winner at t, and it beats the
409 // null_threshold, or the next choice is space, in which case we will use the
410 // null anyway.
411 #if 0 // TODO: unused, remove if still unused after 2020.
412 static bool NullIsBest(const NetworkIO& output, float null_thr,
413  int null_char, int t) {
414  if (output.f(t)[null_char] >= null_thr) return true;
415  if (output.BestLabel(t, null_char, null_char, nullptr) != UNICHAR_SPACE)
416  return false;
417  return output.f(t)[null_char] > output.f(t)[UNICHAR_SPACE];
418 }
419 #endif
420 
421 // Converts the network output to a sequence of labels. Outputs labels, scores
422 // and start xcoords of each char, and each null_char_, with an additional
423 // final xcoord for the end of the output.
424 // The conversion method is determined by internal state.
426  GenericVector<int>* labels,
427  GenericVector<int>* xcoords) {
428  if (SimpleTextOutput()) {
429  LabelsViaSimpleText(outputs, labels, xcoords);
430  } else {
431  LabelsViaReEncode(outputs, labels, xcoords);
432  }
433 }
434 
435 // As LabelsViaCTC except that this function constructs the best path that
436 // contains only legal sequences of subcodes for CJK.
438  GenericVector<int>* labels,
439  GenericVector<int>* xcoords) {
440  if (search_ == nullptr) {
441  search_ =
443  }
444  search_->Decode(output, 1.0, 0.0, RecodeBeamSearch::kMinCertainty, nullptr);
445  search_->ExtractBestPathAsLabels(labels, xcoords);
446 }
447 
448 // Converts the network output to a sequence of labels, with scores, using
449 // the simple character model (each position is a char, and the null_char_ is
450 // mainly intended for tail padding.)
452  GenericVector<int>* labels,
453  GenericVector<int>* xcoords) {
454  labels->truncate(0);
455  xcoords->truncate(0);
456  const int width = output.Width();
457  for (int t = 0; t < width; ++t) {
458  float score = 0.0f;
459  const int label = output.BestLabel(t, &score);
460  if (label != null_char_) {
461  labels->push_back(label);
462  xcoords->push_back(t);
463  }
464  }
465  xcoords->push_back(width);
466 }
467 
468 // Returns a string corresponding to the label starting at start. Sets *end
469 // to the next start and if non-null, *decoded to the unichar id.
471  int start, int* end, int* decoded) {
472  *end = start + 1;
473  if (IsRecoding()) {
474  // Decode labels via recoder_.
475  RecodedCharID code;
476  if (labels[start] == null_char_) {
477  if (decoded != nullptr) {
478  code.Set(0, null_char_);
479  *decoded = recoder_.DecodeUnichar(code);
480  }
481  return "<null>";
482  }
483  int index = start;
484  while (index < labels.size() &&
486  code.Set(code.length(), labels[index++]);
487  while (index < labels.size() && labels[index] == null_char_) ++index;
488  int uni_id = recoder_.DecodeUnichar(code);
489  // If the next label isn't a valid first code, then we need to continue
490  // extending even if we have a valid uni_id from this prefix.
491  if (uni_id != INVALID_UNICHAR_ID &&
492  (index == labels.size() ||
494  recoder_.IsValidFirstCode(labels[index]))) {
495  *end = index;
496  if (decoded != nullptr) *decoded = uni_id;
497  if (uni_id == UNICHAR_SPACE) return " ";
498  return GetUnicharset().get_normed_unichar(uni_id);
499  }
500  }
501  return "<Undecodable>";
502  } else {
503  if (decoded != nullptr) *decoded = labels[start];
504  if (labels[start] == null_char_) return "<null>";
505  if (labels[start] == UNICHAR_SPACE) return " ";
506  return GetUnicharset().get_normed_unichar(labels[start]);
507  }
508 }
509 
510 // Returns a string corresponding to a given single label id, falling back to
511 // a default of ".." for part of a multi-label unichar-id.
512 const char* LSTMRecognizer::DecodeSingleLabel(int label) {
513  if (label == null_char_) return "<null>";
514  if (IsRecoding()) {
515  // Decode label via recoder_.
516  RecodedCharID code;
517  code.Set(0, label);
518  label = recoder_.DecodeUnichar(code);
519  if (label == INVALID_UNICHAR_ID) return ".."; // Part of a bigger code.
520  }
521  if (label == UNICHAR_SPACE) return " ";
522  return GetUnicharset().get_normed_unichar(label);
523 }
524 
525 } // namespace tesseract.
void Decode(const NetworkIO &output, double dict_ratio, double cert_offset, double worst_dict_cert, const UNICHARSET *charset, int lstm_choice_mode=0)
Definition: recodebeam.cpp:82
const double kDictRatio
NetworkScratch scratch_space_
bool save_to_file(const char *const filename) const
Definition: unicharset.h:350
void Text(int x, int y, const char *mystring)
Definition: scrollview.cpp:652
Definition: rect.h:34
void DebugActivationRange(const NetworkIO &outputs, const char *label, int best_choice, int x_start, int x_end)
bool Serialize(const char *data, size_t count=1)
Definition: serialis.cpp:147
const char * DecodeSingleLabel(int label)
char * user_patterns_suffix
Definition: dict.h:573
bool Serialize(const TessdataManager *mgr, TFile *fp) const
bool IsComponentAvailable(TessdataType type) const
Definition: strngs.h:45
bool LoadCharsets(const TessdataManager *mgr)
void LabelsFromOutputs(const NetworkIO &outputs, GenericVector< int > *labels, GenericVector< int > *xcoords)
bool Serialize(TFile *fp) const
virtual void SetRandomizer(TRand *randomizer)
Definition: network.cpp:138
void OutputStats(const NetworkIO &outputs, float *min_output, float *mean_output, float *sd)
const UNICHARSET & GetUnicharset() const
bool IsValidFirstCode(int code) const
void LabelsViaReEncode(const NetworkIO &output, GenericVector< int > *labels, GenericVector< int > *xcoords)
UNICHARSET unicharset
Definition: ccutil.h:71
bool FinishLoad()
Definition: dict.cpp:360
void Set(int index, int value)
static void PreparePixInput(const StaticShape &shape, const Pix *pix, TRand *randomizer, NetworkIO *input)
Definition: input.cpp:111
bool GetComponent(TessdataType type, TFile *fp)
Pix * ToPix() const
Definition: networkio.cpp:286
void LoadLSTM(const STRING &lang, TessdataManager *data_file)
Definition: dict.cpp:300
static const int kMaxCodeLen
void SetupForLoad(DawgCache *dawg_cache)
Definition: dict.cpp:201
STRING DecodeLabels(const GenericVector< int > &labels)
void SetupPassThrough(const UNICHARSET &unicharset)
void add(int32_t value, int32_t count)
Definition: statistc.cpp:99
static const float kMinCertainty
Definition: recodebeam.h:222
int DecodeUnichar(const RecodedCharID &code) const
RecodeBeamSearch * search_
void DisplayForward(const NetworkIO &inputs, const GenericVector< int > &labels, const GenericVector< int > &label_coords, const char *window_name, ScrollView **window)
const char * get_normed_unichar(UNICHAR_ID unichar_id) const
Definition: unicharset.h:828
virtual void CacheXScaleFactor(int factor)
Definition: network.h:214
bool SimpleTextOutput() const
bool Load(const ParamsVectors *params, const char *lang, TessdataManager *mgr)
static void Update()
Definition: scrollview.cpp:709
void ExtractBestPathAsLabels(GenericVector< int > *labels, GenericVector< int > *xcoords) const
Definition: recodebeam.cpp:139
void TextAttributes(const char *font, int pixel_size, bool bold, bool italic, bool underlined)
Definition: scrollview.cpp:635
int32_t min_bucket() const
Definition: statistc.cpp:204
virtual StaticShape InputShape() const
Definition: network.h:126
void LabelsViaSimpleText(const NetworkIO &output, GenericVector< int > *labels, GenericVector< int > *xcoords)
const char * DecodeLabel(const GenericVector< int > &labels, int start, int *end, int *decoded)
virtual void Forward(bool debug, const NetworkIO &input, const TransposedArray *input_transpose, NetworkScratch *scratch, NetworkIO *output)=0
char * user_patterns_file
Definition: dict.h:571
void Pen(Color color)
Definition: scrollview.cpp:719
void set_int_mode(bool is_quantized)
Definition: networkio.h:130
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:36
void truncate(int size)
char * user_words_suffix
Definition: dict.h:569
int push_back(T object)
void RecognizeLine(const ImageData &image_data, bool invert, bool debug, double worst_dict_cert, const TBOX &line_box, PointerVector< WERD_RES > *words, int lstm_choice_mode=0)
char * user_words_file
Definition: dict.h:567
int NumFeatures() const
Definition: networkio.h:111
bool DeSerialize(bool swap, FILE *fp)
Definition: strngs.cpp:159
static Pix * PrepareLSTMInputs(const ImageData &image_data, const Network *network, int min_width, TRand *randomizer, float *image_scale)
Definition: input.cpp:83
bool DeSerialize(char *data, size_t count=1)
Definition: serialis.cpp:103
bool IsTraining() const
Definition: network.h:114
void DisplayLSTMOutput(const GenericVector< int > &labels, const GenericVector< int > &xcoords, int height, ScrollView *window)
bool load_from_file(const char *const filename, bool skip_fragments)
Definition: unicharset.h:388
int32_t get_total() const
Definition: statistc.h:84
static Network * CreateFromFile(TFile *fp)
Definition: network.cpp:187
virtual int XScaleFactor() const
Definition: network.h:208
int EncodeUnichar(int unichar_id, RecodedCharID *code) const
void Line(int x1, int y1, int x2, int y2)
Definition: scrollview.cpp:532
float * f(int t)
Definition: networkio.h:115
int BestLabel(int t, float *score) const
Definition: networkio.h:161
static TESS_API DawgCache * GlobalDawgCache()
Definition: dict.cpp:193
static void ClearWindow(bool tess_coords, const char *window_name, int width, int height, ScrollView **window)
Definition: network.cpp:312
bool LoadDictionary(const ParamsVectors *params, const char *lang, TessdataManager *mgr)
bool Serialize(FILE *fp) const
Definition: strngs.cpp:146
void ExtractBestPathAsWords(const TBOX &line_box, float scale_factor, bool debug, const UNICHARSET *unicharset, PointerVector< WERD_RES > *words, int lstm_choice_mode=0)
Definition: recodebeam.cpp:177
void DebugActivationPath(const NetworkIO &outputs, const GenericVector< int > &labels, const GenericVector< int > &xcoords)
int size() const
Definition: genericvector.h:70
Definition: statistc.h:31
bool DeSerialize(const TessdataManager *mgr, TFile *fp)
const double kCertOffset
double mean() const
Definition: statistc.cpp:133
virtual bool Serialize(TFile *fp) const
Definition: network.cpp:151
static int DisplayImage(Pix *pix, ScrollView *window)
Definition: network.cpp:335
double sd() const
Definition: statistc.cpp:149
int Width() const
Definition: networkio.h:107