21 #ifndef THIRD_PARTY_TESSERACT_LSTM_RECODEBEAM_H_ 22 #define THIRD_PARTY_TESSERACT_LSTM_RECODEBEAM_H_ 107 bool word_start,
bool end,
bool dup,
float cert,
float s,
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,
209 int lstm_choice_mode = 0);
216 std::vector< std::vector<std::pair<const char*, float>>>
timesteps;
252 for (
int i = 0; i <
NC_COUNT; ++i) {
253 best_initial_dawgs_[i] = empty;
272 RecodeNode best_initial_dawgs_[
NC_COUNT];
274 using TopPair = KDPairInc<float, int>;
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,
318 void ContinueUnichar(
int code,
int unichar_id,
float cert,
319 float worst_dict_cert,
float dict_ratio,
bool use_dawgs,
324 void ContinueDawg(
int code,
int unichar_id,
float cert,
NodeContinuation cont,
325 const RecodeNode* prev, RecodeBeam* step);
328 void PushInitialDawgIfBetter(
int code,
int unichar_id,
PermuterType permuter,
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,
342 void PushHeapIfBetter(
int max_size,
int code,
int unichar_id,
343 PermuterType permuter,
bool dawg_start,
bool word_start,
344 bool end,
bool dup,
float cert,
const RecodeNode* prev,
348 void PushHeapIfBetter(
int max_size, RecodeNode* node,
RecodeHeap* heap);
351 bool UpdateHeapIfMatched(RecodeNode* new_node,
RecodeHeap* heap);
353 uint64_t ComputeCodeHash(
int code,
bool dup,
const RecodeNode* prev)
const;
362 void ExtractPath(
const RecodeNode* node,
368 void DebugUnicharPath(
const UNICHARSET* unicharset,
378 const UnicharCompress& recoder_;
380 PointerVector<RecodeBeam> beam_;
390 GenericHeap<TopPair> top_heap_;
395 bool space_delimited_;
398 bool is_simple_text_;
405 #endif // THIRD_PARTY_TESSERACT_LSTM_RECODEBEAM_H_
void ExtractBestPathAsLabels(GenericVector< int > *labels, GenericVector< int > *xcoords) const
static const int kMaxCodeLen
static int BeamIndex(bool is_dawg, NodeContinuation cont, int length)
void Decode(const NetworkIO &output, double dict_ratio, double cert_offset, double worst_dict_cert, const UNICHARSET *charset, int lstm_choice_mode=0)
GenericHeap< RecodePair > RecodeHeap
static int LengthFromBeamsIndex(int index)
static NodeContinuation ContinuationFromBeamsIndex(int index)
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)
static const int kNumLengths
void Print(int null_char, const UNICHARSET &unicharset, int depth) const
std::vector< std::vector< std::pair< const char *, float > > > timesteps
RecodeNode(RecodeNode &src)
void DebugBeams(const UNICHARSET &unicharset) const
static bool IsDawgFromBeamsIndex(int index)
DawgPositionVector * dawgs
RecodeBeamSearch(const UnicharCompress &recoder, int null_char, bool simple_text, Dict *dict)
static const float kMinCertainty
void ExtractBestPathAsUnicharIds(bool debug, const UNICHARSET *unicharset, GenericVector< int > *unichar_ids, GenericVector< float > *certs, GenericVector< float > *ratings, GenericVector< int > *xcoords) const
RecodeNode & operator=(RecodeNode &src)
static const int kNumBeams
void ExtractBestPathAsWords(const TBOX &line_box, float scale_factor, bool debug, const UNICHARSET *unicharset, PointerVector< WERD_RES > *words, int lstm_choice_mode=0)