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