tesseract  v4.0.0-17-g361f3264
Open Source OCR Engine
tesseract::RecodeBeamSearch Class Reference

#include <recodebeam.h>

Collaboration diagram for tesseract::RecodeBeamSearch:

Classes

struct  RecodeBeam
 

Public Member Functions

 RecodeBeamSearch (const UnicharCompress &recoder, int null_char, bool simple_text, Dict *dict)
 
void Decode (const NetworkIO &output, double dict_ratio, double cert_offset, double worst_dict_cert, const UNICHARSET *charset, int lstm_choice_mode=0)
 
void Decode (const GENERIC_2D_ARRAY< float > &output, double dict_ratio, double cert_offset, double worst_dict_cert, const UNICHARSET *charset)
 
void ExtractBestPathAsLabels (GenericVector< int > *labels, GenericVector< int > *xcoords) const
 
void ExtractBestPathAsUnicharIds (bool debug, const UNICHARSET *unicharset, GenericVector< int > *unichar_ids, GenericVector< float > *certs, GenericVector< float > *ratings, GenericVector< int > *xcoords) const
 
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
 

Static Public Member Functions

static int LengthFromBeamsIndex (int index)
 
static NodeContinuation ContinuationFromBeamsIndex (int index)
 
static bool IsDawgFromBeamsIndex (int index)
 
static int BeamIndex (bool is_dawg, NodeContinuation cont, int length)
 

Public Attributes

std::vector< std::vector< std::pair< const char *, float > > > timesteps
 

Static Public Attributes

static const float kMinCertainty = -20.0f
 
static const int kNumLengths = RecodedCharID::kMaxCodeLen + 1
 
static const int kNumBeams = 2 * NC_COUNT * kNumLengths
 

Private Types

using TopPair = KDPairInc< float, int >
 

Private Member Functions

void DebugBeamPos (const UNICHARSET &unicharset, const RecodeHeap &heap) const
 
WERD_RESInitializeWord (bool leading_space, const TBOX &line_box, int word_start, int word_end, float space_certainty, const UNICHARSET *unicharset, const GenericVector< int > &xcoords, float scale_factor)
 
void ComputeTopN (const float *outputs, int num_outputs, int top_n)
 
void DecodeStep (const float *outputs, int t, double dict_ratio, double cert_offset, double worst_dict_cert, const UNICHARSET *charset, bool debug=false)
 
void SaveMostCertainChoices (const float *outputs, int num_outputs, const UNICHARSET *charset, int xCoord)
 
void ContinueContext (const RecodeNode *prev, int index, const float *outputs, TopNState top_n_flag, double dict_ratio, double cert_offset, double worst_dict_cert, RecodeBeam *step)
 
void ContinueUnichar (int code, int unichar_id, float cert, float worst_dict_cert, float dict_ratio, bool use_dawgs, NodeContinuation cont, const RecodeNode *prev, RecodeBeam *step)
 
void ContinueDawg (int code, int unichar_id, float cert, NodeContinuation cont, const RecodeNode *prev, RecodeBeam *step)
 
void PushInitialDawgIfBetter (int code, int unichar_id, PermuterType permuter, bool start, bool end, float cert, NodeContinuation cont, const RecodeNode *prev, RecodeBeam *step)
 
void PushDupOrNoDawgIfBetter (int length, bool dup, int code, int unichar_id, float cert, float worst_dict_cert, float dict_ratio, bool use_dawgs, NodeContinuation cont, const RecodeNode *prev, RecodeBeam *step)
 
void PushHeapIfBetter (int max_size, int code, int unichar_id, PermuterType permuter, bool dawg_start, bool word_start, bool end, bool dup, float cert, const RecodeNode *prev, DawgPositionVector *d, RecodeHeap *heap)
 
void PushHeapIfBetter (int max_size, RecodeNode *node, RecodeHeap *heap)
 
bool UpdateHeapIfMatched (RecodeNode *new_node, RecodeHeap *heap)
 
uint64_t ComputeCodeHash (int code, bool dup, const RecodeNode *prev) const
 
void ExtractBestPaths (GenericVector< const RecodeNode *> *best_nodes, GenericVector< const RecodeNode *> *second_nodes) const
 
void ExtractPath (const RecodeNode *node, GenericVector< const RecodeNode *> *path) const
 
void DebugPath (const UNICHARSET *unicharset, const GenericVector< const RecodeNode *> &path) const
 
void DebugUnicharPath (const UNICHARSET *unicharset, const GenericVector< const RecodeNode *> &path, const GenericVector< int > &unichar_ids, const GenericVector< float > &certs, const GenericVector< float > &ratings, const GenericVector< int > &xcoords) const
 

Static Private Member Functions

static void ExtractPathAsUnicharIds (const GenericVector< const RecodeNode *> &best_nodes, GenericVector< int > *unichar_ids, GenericVector< float > *certs, GenericVector< float > *ratings, GenericVector< int > *xcoords, std::deque< std::pair< int, int >> *best_choices=nullptr)
 

Private Attributes

const UnicharCompressrecoder_
 
PointerVector< RecodeBeambeam_
 
int beam_size_
 
GenericVector< TopNStatetop_n_flags_
 
int top_code_
 
int second_code_
 
GenericHeap< TopPairtop_heap_
 
Dictdict_
 
bool space_delimited_
 
bool is_simple_text_
 
int null_char_
 

Static Private Attributes

static const int kBeamWidths [RecodedCharID::kMaxCodeLen+1]
 

Member Typedef Documentation

◆ TopPair

using tesseract::RecodeBeamSearch::TopPair = KDPairInc<float, int>
private

Constructor & Destructor Documentation

◆ RecodeBeamSearch()

tesseract::RecodeBeamSearch::RecodeBeamSearch ( const UnicharCompress recoder,
int  null_char,
bool  simple_text,
Dict dict 
)

Member Function Documentation

◆ BeamIndex()

static int tesseract::RecodeBeamSearch::BeamIndex ( bool  is_dawg,
NodeContinuation  cont,
int  length 
)
inlinestatic

◆ ComputeCodeHash()

uint64_t tesseract::RecodeBeamSearch::ComputeCodeHash ( int  code,
bool  dup,
const RecodeNode prev 
) const
private

◆ ComputeTopN()

void tesseract::RecodeBeamSearch::ComputeTopN ( const float *  outputs,
int  num_outputs,
int  top_n 
)
private

◆ ContinuationFromBeamsIndex()

static NodeContinuation tesseract::RecodeBeamSearch::ContinuationFromBeamsIndex ( int  index)
inlinestatic

◆ ContinueContext()

void tesseract::RecodeBeamSearch::ContinueContext ( const RecodeNode prev,
int  index,
const float *  outputs,
TopNState  top_n_flag,
double  dict_ratio,
double  cert_offset,
double  worst_dict_cert,
RecodeBeam step 
)
private

◆ ContinueDawg()

void tesseract::RecodeBeamSearch::ContinueDawg ( int  code,
int  unichar_id,
float  cert,
NodeContinuation  cont,
const RecodeNode prev,
RecodeBeam step 
)
private

◆ ContinueUnichar()

void tesseract::RecodeBeamSearch::ContinueUnichar ( int  code,
int  unichar_id,
float  cert,
float  worst_dict_cert,
float  dict_ratio,
bool  use_dawgs,
NodeContinuation  cont,
const RecodeNode prev,
RecodeBeam step 
)
private

◆ DebugBeamPos()

void tesseract::RecodeBeamSearch::DebugBeamPos ( const UNICHARSET unicharset,
const RecodeHeap heap 
) const
private

◆ DebugBeams()

void tesseract::RecodeBeamSearch::DebugBeams ( const UNICHARSET unicharset) const

◆ DebugPath()

void tesseract::RecodeBeamSearch::DebugPath ( const UNICHARSET unicharset,
const GenericVector< const RecodeNode *> &  path 
) const
private

◆ DebugUnicharPath()

void tesseract::RecodeBeamSearch::DebugUnicharPath ( const UNICHARSET unicharset,
const GenericVector< const RecodeNode *> &  path,
const GenericVector< int > &  unichar_ids,
const GenericVector< float > &  certs,
const GenericVector< float > &  ratings,
const GenericVector< int > &  xcoords 
) const
private

◆ Decode() [1/2]

void tesseract::RecodeBeamSearch::Decode ( const NetworkIO output,
double  dict_ratio,
double  cert_offset,
double  worst_dict_cert,
const UNICHARSET charset,
int  lstm_choice_mode = 0 
)

◆ Decode() [2/2]

void tesseract::RecodeBeamSearch::Decode ( const GENERIC_2D_ARRAY< float > &  output,
double  dict_ratio,
double  cert_offset,
double  worst_dict_cert,
const UNICHARSET charset 
)

◆ DecodeStep()

void tesseract::RecodeBeamSearch::DecodeStep ( const float *  outputs,
int  t,
double  dict_ratio,
double  cert_offset,
double  worst_dict_cert,
const UNICHARSET charset,
bool  debug = false 
)
private

◆ ExtractBestPathAsLabels()

void tesseract::RecodeBeamSearch::ExtractBestPathAsLabels ( GenericVector< int > *  labels,
GenericVector< int > *  xcoords 
) const

◆ ExtractBestPathAsUnicharIds()

void tesseract::RecodeBeamSearch::ExtractBestPathAsUnicharIds ( bool  debug,
const UNICHARSET unicharset,
GenericVector< int > *  unichar_ids,
GenericVector< float > *  certs,
GenericVector< float > *  ratings,
GenericVector< int > *  xcoords 
) const

◆ ExtractBestPathAsWords()

void tesseract::RecodeBeamSearch::ExtractBestPathAsWords ( const TBOX line_box,
float  scale_factor,
bool  debug,
const UNICHARSET unicharset,
PointerVector< WERD_RES > *  words,
int  lstm_choice_mode = 0 
)

◆ ExtractBestPaths()

void tesseract::RecodeBeamSearch::ExtractBestPaths ( GenericVector< const RecodeNode *> *  best_nodes,
GenericVector< const RecodeNode *> *  second_nodes 
) const
private

◆ ExtractPath()

void tesseract::RecodeBeamSearch::ExtractPath ( const RecodeNode node,
GenericVector< const RecodeNode *> *  path 
) const
private

◆ ExtractPathAsUnicharIds()

void tesseract::RecodeBeamSearch::ExtractPathAsUnicharIds ( const GenericVector< const RecodeNode *> &  best_nodes,
GenericVector< int > *  unichar_ids,
GenericVector< float > *  certs,
GenericVector< float > *  ratings,
GenericVector< int > *  xcoords,
std::deque< std::pair< int, int >> *  best_choices = nullptr 
)
staticprivate

◆ InitializeWord()

WERD_RES * tesseract::RecodeBeamSearch::InitializeWord ( bool  leading_space,
const TBOX line_box,
int  word_start,
int  word_end,
float  space_certainty,
const UNICHARSET unicharset,
const GenericVector< int > &  xcoords,
float  scale_factor 
)
private

◆ IsDawgFromBeamsIndex()

static bool tesseract::RecodeBeamSearch::IsDawgFromBeamsIndex ( int  index)
inlinestatic

◆ LengthFromBeamsIndex()

static int tesseract::RecodeBeamSearch::LengthFromBeamsIndex ( int  index)
inlinestatic

◆ PushDupOrNoDawgIfBetter()

void tesseract::RecodeBeamSearch::PushDupOrNoDawgIfBetter ( int  length,
bool  dup,
int  code,
int  unichar_id,
float  cert,
float  worst_dict_cert,
float  dict_ratio,
bool  use_dawgs,
NodeContinuation  cont,
const RecodeNode prev,
RecodeBeam step 
)
private

◆ PushHeapIfBetter() [1/2]

void tesseract::RecodeBeamSearch::PushHeapIfBetter ( int  max_size,
int  code,
int  unichar_id,
PermuterType  permuter,
bool  dawg_start,
bool  word_start,
bool  end,
bool  dup,
float  cert,
const RecodeNode prev,
DawgPositionVector d,
RecodeHeap heap 
)
private

◆ PushHeapIfBetter() [2/2]

void tesseract::RecodeBeamSearch::PushHeapIfBetter ( int  max_size,
RecodeNode node,
RecodeHeap heap 
)
private

◆ PushInitialDawgIfBetter()

void tesseract::RecodeBeamSearch::PushInitialDawgIfBetter ( int  code,
int  unichar_id,
PermuterType  permuter,
bool  start,
bool  end,
float  cert,
NodeContinuation  cont,
const RecodeNode prev,
RecodeBeam step 
)
private

◆ SaveMostCertainChoices()

void tesseract::RecodeBeamSearch::SaveMostCertainChoices ( const float *  outputs,
int  num_outputs,
const UNICHARSET charset,
int  xCoord 
)
private

◆ UpdateHeapIfMatched()

bool tesseract::RecodeBeamSearch::UpdateHeapIfMatched ( RecodeNode new_node,
RecodeHeap heap 
)
private

Member Data Documentation

◆ beam_

PointerVector<RecodeBeam> tesseract::RecodeBeamSearch::beam_
private

◆ beam_size_

int tesseract::RecodeBeamSearch::beam_size_
private

◆ dict_

Dict* tesseract::RecodeBeamSearch::dict_
private

◆ is_simple_text_

bool tesseract::RecodeBeamSearch::is_simple_text_
private

◆ kBeamWidths

const int tesseract::RecodeBeamSearch::kBeamWidths
staticprivate
Initial value:
= {
5, 10, 16, 16, 16, 16, 16, 16, 16, 16,
}

◆ kMinCertainty

const float tesseract::RecodeBeamSearch::kMinCertainty = -20.0f
static

◆ kNumBeams

const int tesseract::RecodeBeamSearch::kNumBeams = 2 * NC_COUNT * kNumLengths
static

◆ kNumLengths

const int tesseract::RecodeBeamSearch::kNumLengths = RecodedCharID::kMaxCodeLen + 1
static

◆ null_char_

int tesseract::RecodeBeamSearch::null_char_
private

◆ recoder_

const UnicharCompress& tesseract::RecodeBeamSearch::recoder_
private

◆ second_code_

int tesseract::RecodeBeamSearch::second_code_
private

◆ space_delimited_

bool tesseract::RecodeBeamSearch::space_delimited_
private

◆ timesteps

std::vector< std::vector<std::pair<const char*, float> > > tesseract::RecodeBeamSearch::timesteps

◆ top_code_

int tesseract::RecodeBeamSearch::top_code_
private

◆ top_heap_

GenericHeap<TopPair> tesseract::RecodeBeamSearch::top_heap_
private

◆ top_n_flags_

GenericVector<TopNState> tesseract::RecodeBeamSearch::top_n_flags_
private

The documentation for this class was generated from the following files: