@@ -81,17 +81,17 @@ RecodeBeamSearch::RecodeBeamSearch(const UnicharCompress& recoder,
81
81
// Decodes the set of network outputs, storing the lattice internally.
82
82
void RecodeBeamSearch::Decode (const NetworkIO& output, double dict_ratio,
83
83
double cert_offset, double worst_dict_cert,
84
- const UNICHARSET* charset, int glyph_confidence ) {
84
+ const UNICHARSET* charset, int lstm_choice_mode ) {
85
85
beam_size_ = 0 ;
86
86
int width = output.Width ();
87
- if (glyph_confidence )
87
+ if (lstm_choice_mode )
88
88
timesteps.clear ();
89
89
for (int t = 0 ; t < width; ++t) {
90
90
ComputeTopN (output.f (t), output.NumFeatures (), kBeamWidths [0 ]);
91
91
DecodeStep (output.f (t), t, dict_ratio, cert_offset, worst_dict_cert,
92
92
charset);
93
- if (glyph_confidence ) {
94
- SaveMostCertainGlyphs (output.f (t), output.NumFeatures (), charset, t);
93
+ if (lstm_choice_mode ) {
94
+ SaveMostCertainChoices (output.f (t), output.NumFeatures (), charset, t);
95
95
}
96
96
}
97
97
}
@@ -107,33 +107,33 @@ void RecodeBeamSearch::Decode(const GENERIC_2D_ARRAY<float>& output,
107
107
}
108
108
}
109
109
110
- void RecodeBeamSearch::SaveMostCertainGlyphs (const float * outputs,
110
+ void RecodeBeamSearch::SaveMostCertainChoices (const float * outputs,
111
111
int num_outputs,
112
112
const UNICHARSET* charset,
113
113
int xCoord) {
114
- std::vector<std::pair<const char *, float >> glyphs ;
114
+ std::vector<std::pair<const char *, float >> choices ;
115
115
int pos = 0 ;
116
116
for (int i = 0 ; i < num_outputs; ++i) {
117
117
if (outputs[i] >= 0 .01f ) {
118
- const char * charakter ;
118
+ const char * character ;
119
119
if (i + 2 >= num_outputs) {
120
- charakter = " " ;
120
+ character = " " ;
121
121
} else if (i > 0 ) {
122
- charakter = charset->id_to_unichar_ext (i + 2 );
122
+ character = charset->id_to_unichar_ext (i + 2 );
123
123
} else {
124
- charakter = charset->id_to_unichar_ext (i);
124
+ character = charset->id_to_unichar_ext (i);
125
125
}
126
126
pos = 0 ;
127
- // order the possible glyphs within one timestep
127
+ // order the possible choices within one timestep
128
128
// beginning with the most likely
129
- while (glyphs .size () > pos && glyphs [pos].second > outputs[i]) {
129
+ while (choices .size () > pos && choices [pos].second > outputs[i]) {
130
130
pos++;
131
131
}
132
- glyphs .insert (glyphs .begin () + pos,
133
- std::pair<const char *, float >(charakter , outputs[i]));
132
+ choices .insert (choices .begin () + pos,
133
+ std::pair<const char *, float >(character , outputs[i]));
134
134
}
135
135
}
136
- timesteps.push_back (glyphs );
136
+ timesteps.push_back (choices );
137
137
}
138
138
139
139
// Returns the best path as labels/scores/xcoords similar to simple CTC.
@@ -179,15 +179,15 @@ void RecodeBeamSearch::ExtractBestPathAsWords(const TBOX& line_box,
179
179
float scale_factor, bool debug,
180
180
const UNICHARSET* unicharset,
181
181
PointerVector<WERD_RES>* words,
182
- int glyph_confidence ) {
182
+ int lstm_choice_mode ) {
183
183
words->truncate (0 );
184
184
GenericVector<int > unichar_ids;
185
185
GenericVector<float > certs;
186
186
GenericVector<float > ratings;
187
187
GenericVector<int > xcoords;
188
188
GenericVector<const RecodeNode*> best_nodes;
189
189
GenericVector<const RecodeNode*> second_nodes;
190
- std::deque<std::pair<int ,int >> best_glyphs ;
190
+ std::deque<std::pair<int ,int >> best_choices ;
191
191
ExtractBestPaths (&best_nodes, &second_nodes);
192
192
if (debug) {
193
193
DebugPath (unicharset, best_nodes);
@@ -199,15 +199,15 @@ void RecodeBeamSearch::ExtractBestPathAsWords(const TBOX& line_box,
199
199
}
200
200
int current_char;
201
201
int timestepEnd = 0 ;
202
- // if glyph confidence is required in granularity level 2 it stores the x
203
- // Coordinates of every chosen character to match the alternative glyphs to it
204
- if (glyph_confidence == 2 ) {
202
+ // if lstm choice mode is required in granularity level 2 it stores the x
203
+ // Coordinates of every chosen character to match the alternative choices to it
204
+ if (lstm_choice_mode == 2 ) {
205
205
ExtractPathAsUnicharIds (best_nodes, &unichar_ids, &certs, &ratings,
206
- &xcoords, &best_glyphs );
207
- if (best_glyphs .size () > 0 ) {
208
- current_char = best_glyphs .front ().first ;
209
- timestepEnd = best_glyphs .front ().second ;
210
- best_glyphs .pop_front ();
206
+ &xcoords, &best_choices );
207
+ if (best_choices .size () > 0 ) {
208
+ current_char = best_choices .front ().first ;
209
+ timestepEnd = best_choices .front ().second ;
210
+ best_choices .pop_front ();
211
211
}
212
212
} else {
213
213
ExtractPathAsUnicharIds (best_nodes, &unichar_ids, &certs, &ratings,
@@ -243,25 +243,25 @@ void RecodeBeamSearch::ExtractBestPathAsWords(const TBOX& line_box,
243
243
WERD_RES* word_res = InitializeWord (
244
244
leading_space, line_box, word_start, word_end,
245
245
std::min (space_cert, prev_space_cert), unicharset, xcoords, scale_factor);
246
- if (glyph_confidence == 1 ) {
246
+ if (lstm_choice_mode == 1 ) {
247
247
for (size_t i = timestepEnd; i < xcoords[word_end]; i++) {
248
248
word_res->timesteps .push_back (timesteps[i]);
249
249
}
250
250
timestepEnd = xcoords[word_end];
251
- } else if (glyph_confidence == 2 ) {
251
+ } else if (lstm_choice_mode == 2 ) {
252
252
float sum = 0 ;
253
- std::vector<std::pair<const char *, float >> glyph_pairs ;
253
+ std::vector<std::pair<const char *, float >> choice_pairs ;
254
254
for (size_t i = timestepEnd; i < xcoords[word_end]; i++) {
255
- for (std::pair<const char *, float > glyph : timesteps[i]) {
256
- if (std::strcmp (glyph .first , " " ) != 0 ) {
257
- sum += glyph .second ;
258
- glyph_pairs .push_back (glyph );
255
+ for (std::pair<const char *, float > choice : timesteps[i]) {
256
+ if (std::strcmp (choice .first , " " ) != 0 ) {
257
+ sum += choice .second ;
258
+ choice_pairs .push_back (choice );
259
259
}
260
260
}
261
- if (best_glyphs .size () > 0 && i == best_glyphs .front ().second - 1
261
+ if (best_choices .size () > 0 && i == best_choices .front ().second - 1
262
262
|| i == xcoords[word_end]-1 ) {
263
263
std::map<const char *, float > summed_propabilities;
264
- for (auto it = glyph_pairs .begin (); it != glyph_pairs .end (); ++it) {
264
+ for (auto it = choice_pairs .begin (); it != choice_pairs .end (); ++it) {
265
265
summed_propabilities[it->first ] += it->second ;
266
266
}
267
267
std::vector<std::pair<const char *, float >> accumulated_timestep;
@@ -282,11 +282,11 @@ void RecodeBeamSearch::ExtractBestPathAsWords(const TBOX& line_box,
282
282
std::pair<const char *,float >(it->first ,
283
283
it->second ));
284
284
}
285
- if (best_glyphs .size () > 0 ) {
286
- current_char = best_glyphs .front ().first ;
287
- best_glyphs .pop_front ();
285
+ if (best_choices .size () > 0 ) {
286
+ current_char = best_choices .front ().first ;
287
+ best_choices .pop_front ();
288
288
}
289
- glyph_pairs .clear ();
289
+ choice_pairs .clear ();
290
290
word_res->timesteps .push_back (accumulated_timestep);
291
291
sum = 0 ;
292
292
}
@@ -366,7 +366,7 @@ void RecodeBeamSearch::ExtractPathAsUnicharIds(
366
366
const GenericVector<const RecodeNode*>& best_nodes,
367
367
GenericVector<int >* unichar_ids, GenericVector<float >* certs,
368
368
GenericVector<float >* ratings, GenericVector<int >* xcoords,
369
- std::deque<std::pair<int ,int >>* best_glyphs ) {
369
+ std::deque<std::pair<int , int >>* best_choices ) {
370
370
unichar_ids->truncate (0 );
371
371
certs->truncate (0 );
372
372
ratings->truncate (0 );
@@ -395,8 +395,8 @@ void RecodeBeamSearch::ExtractPathAsUnicharIds(
395
395
}
396
396
unichar_ids->push_back (unichar_id);
397
397
xcoords->push_back (t);
398
- if (best_glyphs != nullptr ) {
399
- best_glyphs ->push_back (std::pair<int ,int >(unichar_id,t));
398
+ if (best_choices != nullptr ) {
399
+ best_choices ->push_back (std::pair<int , int >(unichar_id, t));
400
400
}
401
401
do {
402
402
double cert = best_nodes[t++]->certainty ;
0 commit comments