21 #ifndef THIRD_PARTY_TESSERACT_LSTM_RECODEBEAM_H_ 22 #define THIRD_PARTY_TESSERACT_LSTM_RECODEBEAM_H_ 26 #include "genericheap.h" 28 #include "networkio.h" 30 #include "unicharcompress.h" 106 RecodeNode(
int c,
int uni_id, PermuterType perm,
bool dawg_start,
107 bool word_start,
bool end,
bool dup,
float cert,
float s,
128 ASSERT_HOST(src.
dawgs ==
nullptr);
132 memcpy(
this, &src,
sizeof(src));
138 void Print(
int null_char,
const UNICHARSET& unicharset,
int depth)
const;
183 bool simple_text,
Dict* dict);
187 void Decode(
const NetworkIO& output,
double dict_ratio,
double cert_offset,
188 double worst_dict_cert,
const UNICHARSET* charset,
189 int lstm_choice_mode = 0);
191 double cert_offset,
double worst_dict_cert,
199 void ExtractBestPathAsUnicharIds(
bool debug,
const UNICHARSET* unicharset,
206 void ExtractBestPathAsWords(
const TBOX& line_box,
float scale_factor,
209 int lstm_choice_mode = 0);
212 void DebugBeams(
const UNICHARSET& unicharset)
const;
216 std::vector< std::vector<std::pair<const char*, float>>>
timesteps;
227 static const int kNumBeams = 2 *
NC_COUNT * kNumLengths;
234 return index / (kNumLengths *
NC_COUNT) > 0;
238 return (is_dawg *
NC_COUNT + cont) * kNumLengths + length;
248 for (
int i = 0; i < kNumBeams; ++i) {
252 for (
int i = 0; i <
NC_COUNT; ++i) {
253 best_initial_dawgs_[i] = empty;
281 static void ExtractPathAsUnicharIds(
285 std::deque<std::pair<int,int>>* best_choices =
nullptr);
289 WERD_RES* InitializeWord(
bool leading_space,
const TBOX& line_box,
290 int word_start,
int word_end,
float space_certainty,
297 void ComputeTopN(
const float* outputs,
int num_outputs,
int top_n);
302 void DecodeStep(
const float* outputs,
int t,
double dict_ratio,
303 double cert_offset,
double worst_dict_cert,
304 const UNICHARSET* charset,
bool debug =
false);
307 void SaveMostCertainChoices(
const float* outputs,
int num_outputs,
const UNICHARSET* charset,
int xCoord);
313 void ContinueContext(
const RecodeNode*
prev,
int index,
const float* outputs,
315 double cert_offset,
double worst_dict_cert,
319 float worst_dict_cert,
float dict_ratio,
bool use_dawgs,
329 bool start,
bool end,
float cert,
335 void PushDupOrNoDawgIfBetter(
int length,
bool dup,
int code,
int unichar_id,
336 float cert,
float worst_dict_cert,
337 float dict_ratio,
bool use_dawgs,
343 PermuterType
permuter,
bool dawg_start,
bool word_start,
368 void DebugUnicharPath(
const UNICHARSET* unicharset,
405 #endif // THIRD_PARTY_TESSERACT_LSTM_RECODEBEAM_H_
Definition: recodebeam.h:87
RecodeNode & operator=(RecodeNode &src)
Definition: recodebeam.h:130
int beam_size_
Definition: recodebeam.h:382
float score
Definition: recodebeam.h:165
bool start_of_dawg
Definition: recodebeam.h:150
RecodeNode(int c, int uni_id, PermuterType perm, bool dawg_start, bool word_start, bool end, bool dup, float cert, float s, const RecodeNode *p, DawgPositionVector *d, uint64_t hash)
Definition: recodebeam.h:106
int second_code_
Definition: recodebeam.h:388
int code
Definition: recodebeam.h:141
int top_code_
Definition: recodebeam.h:387
bool is_simple_text_
Definition: recodebeam.h:398
void Clear()
Definition: recodebeam.h:247
PermuterType permuter
Definition: recodebeam.h:147
Definition: unicharset.h:146
DawgPositionVector * dawgs
Definition: recodebeam.h:169
static int BeamIndex(bool is_dawg, NodeContinuation cont, int length)
Definition: recodebeam.h:237
RecodeNode(RecodeNode &src)
Definition: recodebeam.h:126
Definition: recodebeam.h:179
GenericVector< TopNState > top_n_flags_
Definition: recodebeam.h:385
NodeContinuation
Definition: recodebeam.h:72
Definition: baseapi.cpp:94
Definition: recodebeam.h:88
Definition: recodebeam.h:92
Dict * dict_
Definition: recodebeam.h:392
Definition: recodebeam.h:80
void Print(int null_char, const UNICHARSET &unicharset, int depth) const
Definition: recodebeam.cpp:48
Definition: unicharcompress.h:128
std::vector< std::vector< std::pair< const char *, float > > > timesteps
Definition: recodebeam.h:216
Definition: recodebeam.h:77
TopNState
Definition: recodebeam.h:84
GenericHeap< TopPair > top_heap_
Definition: recodebeam.h:390
Definition: recodebeam.h:245
int null_char_
Definition: recodebeam.h:400
bool duplicate
Definition: recodebeam.h:161
static int LengthFromBeamsIndex(int index)
Definition: recodebeam.h:229
uint64_t code_hash
Definition: recodebeam.h:172
static const int kMaxCodeLen
Definition: unicharcompress.h:37
bool start_of_word
Definition: recodebeam.h:152
bool space_delimited_
Definition: recodebeam.h:395
int unichar_id
Definition: recodebeam.h:143
~RecodeNode()
Definition: recodebeam.h:136
const RecodeNode * prev
Definition: recodebeam.h:167
Definition: pageres.h:169
Definition: recodebeam.h:73
Definition: recodebeam.h:74
Definition: recodebeam.h:85
Definition: networkio.h:39
static const float kMinCertainty
Definition: recodebeam.h:222
Definition: recodebeam.h:86
RecodeNode()
Definition: recodebeam.h:93
static bool IsDawgFromBeamsIndex(int index)
Definition: recodebeam.h:233
const UnicharCompress & recoder_
Definition: recodebeam.h:378
static NodeContinuation ContinuationFromBeamsIndex(int index)
Definition: recodebeam.h:230
bool end_of_word
Definition: recodebeam.h:156
PointerVector< RecodeBeam > beam_
Definition: recodebeam.h:380
float certainty
Definition: recodebeam.h:163