tesseract
5.0.0-alpha-619-ge9db
|
Go to the documentation of this file.
20 #ifndef THIRD_PARTY_TESSERACT_LSTM_RECODEBEAM_H_
21 #define THIRD_PARTY_TESSERACT_LSTM_RECODEBEAM_H_
34 #include <unordered_set>
108 bool word_start,
bool end,
bool dup,
float cert,
float s,
133 memcpy(
this, &src,
sizeof(src));
139 void Print(
int null_char,
const UNICHARSET& unicharset,
int depth)
const;
184 bool simple_text,
Dict* dict);
188 void Decode(
const NetworkIO& output,
double dict_ratio,
double cert_offset,
189 double worst_dict_cert,
const UNICHARSET* charset,
190 int lstm_choice_mode = 0);
192 double cert_offset,
double worst_dict_cert,
196 double cert_offset,
double worst_dict_cert,
198 int lstm_choice_mode = 0);
215 int lstm_choice_mode = 0);
229 bool secondary)
const;
232 std::vector<std::vector<std::pair<const char*, float>>>
235 std::vector<std::vector<std::vector<std::pair<const char*, float>>>>*
239 std::vector< std::vector<std::pair<const char*, float>>>
timesteps;
240 std::vector<std::vector<std::vector<std::pair<const char*, float>>>>
243 std::vector<std::vector<std::pair<const char*, float>>>
ctc_choices;
278 for (
auto & beam : beams_) {
282 for (
auto & best_initial_dawg : best_initial_dawgs_) {
283 best_initial_dawg = empty;
302 RecodeNode best_initial_dawgs_[
NC_COUNT];
304 using TopPair = KDPairInc<float, int>;
311 static void ExtractPathAsUnicharIds(
315 std::vector<int>* character_boundaries =
nullptr);
319 WERD_RES* InitializeWord(
bool leading_space,
const TBOX& line_box,
320 int word_start,
int word_end,
float space_certainty,
327 void ComputeTopN(
const float* outputs,
int num_outputs,
int top_n);
329 void ComputeSecTopN(std::unordered_set<int>* exList,
330 const float* outputs,
int num_outputs,
int top_n);
335 void DecodeStep(
const float* outputs,
int t,
double dict_ratio,
336 double cert_offset,
double worst_dict_cert,
337 const UNICHARSET* charset,
bool debug =
false);
339 void DecodeSecondaryStep(
const float* outputs,
int t,
double dict_ratio,
340 double cert_offset,
double worst_dict_cert,
341 const UNICHARSET* charset,
bool debug =
false);
344 void SaveMostCertainChoices(
const float* outputs,
int num_outputs,
349 static void calculateCharBoundaries(std::vector<int>* starts,
350 std::vector<int>* ends,
358 void ContinueContext(
const RecodeNode* prev,
int index,
const float* outputs,
360 double dict_ratio,
double cert_offset,
361 double worst_dict_cert, RecodeBeam* step);
363 void ContinueUnichar(
int code,
int unichar_id,
float cert,
364 float worst_dict_cert,
float dict_ratio,
bool use_dawgs,
369 void ContinueDawg(
int code,
int unichar_id,
float cert,
NodeContinuation cont,
370 const RecodeNode* prev, RecodeBeam* step);
373 void PushInitialDawgIfBetter(
int code,
int unichar_id,
PermuterType permuter,
374 bool start,
bool end,
float cert,
380 void PushDupOrNoDawgIfBetter(
int length,
bool dup,
int code,
int unichar_id,
381 float cert,
float worst_dict_cert,
382 float dict_ratio,
bool use_dawgs,
387 void PushHeapIfBetter(
int max_size,
int code,
int unichar_id,
388 PermuterType permuter,
bool dawg_start,
bool word_start,
389 bool end,
bool dup,
float cert,
const RecodeNode* prev,
393 void PushHeapIfBetter(
int max_size, RecodeNode* node,
RecodeHeap* heap);
396 bool UpdateHeapIfMatched(RecodeNode* new_node,
RecodeHeap* heap);
398 uint64_t ComputeCodeHash(
int code,
bool dup,
const RecodeNode* prev)
const;
407 void ExtractPath(
const RecodeNode* node,
409 void ExtractPath(
const RecodeNode* node,
416 void DebugUnicharPath(
const UNICHARSET* unicharset,
426 const UnicharCompress& recoder_;
428 PointerVector<RecodeBeam> beam_;
430 PointerVector<RecodeBeam> secondary_beam_;
440 GenericHeap<TopPair> top_heap_;
445 bool space_delimited_;
448 bool is_simple_text_;
455 #endif // THIRD_PARTY_TESSERACT_LSTM_RECODEBEAM_H_
static constexpr float kMinCertainty
std::vector< std::unordered_set< int > > excludedUnichars
std::vector< std::vector< std::pair< const char *, float > > > ctc_choices
RecodeNode & operator=(RecodeNode &src)
RecodeNode(RecodeNode &src)
static int LengthFromBeamsIndex(int index)
std::vector< std::vector< std::pair< const char *, float > > > timesteps
void Decode(const NetworkIO &output, double dict_ratio, double cert_offset, double worst_dict_cert, const UNICHARSET *charset, int lstm_choice_mode=0)
void PrintBeam2(bool uids, int num_outputs, const UNICHARSET *charset, bool secondary) const
void extractSymbolChoices(const UNICHARSET *unicharset)
DawgPositionVector * dawgs
static bool IsDawgFromBeamsIndex(int index)
static const int kNumLengths
void DecodeSecondaryBeams(const NetworkIO &output, double dict_ratio, double cert_offset, double worst_dict_cert, const UNICHARSET *charset, int lstm_choice_mode=0)
static const int kNumBeams
void segmentTimestepsByCharacters()
static int BeamIndex(bool is_dawg, NodeContinuation cont, int length)
static NodeContinuation ContinuationFromBeamsIndex(int index)
static const int kMaxCodeLen
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)
std::vector< std::vector< std::pair< const char *, float > > > combineSegmentedTimesteps(std::vector< std::vector< std::vector< std::pair< const char *, float >>>> *segmentedTimesteps)
void ExtractBestPathAsWords(const TBOX &line_box, float scale_factor, bool debug, const UNICHARSET *unicharset, PointerVector< WERD_RES > *words, int lstm_choice_mode=0)
void DebugBeams(const UNICHARSET &unicharset) const
std::vector< int > character_boundaries_
GenericHeap< RecodePair > RecodeHeap
void ExtractBestPathAsUnicharIds(bool debug, const UNICHARSET *unicharset, GenericVector< int > *unichar_ids, GenericVector< float > *certs, GenericVector< float > *ratings, GenericVector< int > *xcoords) const
RecodeBeamSearch(const UnicharCompress &recoder, int null_char, bool simple_text, Dict *dict)
void Print(int null_char, const UNICHARSET &unicharset, int depth) const
void ExtractBestPathAsLabels(GenericVector< int > *labels, GenericVector< int > *xcoords) const
std::vector< std::vector< std::vector< std::pair< const char *, float > > > > segmentedTimesteps