@@ -55,9 +55,9 @@ LSTMRecognizer::LSTMRecognizer()
55
55
training_iteration_(0 ),
56
56
sample_iteration_(0 ),
57
57
null_char_(UNICHAR_BROKEN),
58
- weight_range_(0 .0f ),
59
58
learning_rate_(0 .0f ),
60
59
momentum_(0 .0f ),
60
+ adam_beta_(0 .0f ),
61
61
dict_(NULL ),
62
62
search_(NULL ),
63
63
debug_win_(NULL ) {}
@@ -94,7 +94,7 @@ bool LSTMRecognizer::Serialize(const TessdataManager* mgr, TFile* fp) const {
94
94
if (fp->FWrite (&sample_iteration_, sizeof (sample_iteration_), 1 ) != 1 )
95
95
return false ;
96
96
if (fp->FWrite (&null_char_, sizeof (null_char_), 1 ) != 1 ) return false ;
97
- if (fp->FWrite (&weight_range_ , sizeof (weight_range_ ), 1 ) != 1 ) return false ;
97
+ if (fp->FWrite (&adam_beta_ , sizeof (adam_beta_ ), 1 ) != 1 ) return false ;
98
98
if (fp->FWrite (&learning_rate_, sizeof (learning_rate_), 1 ) != 1 ) return false ;
99
99
if (fp->FWrite (&momentum_, sizeof (momentum_), 1 ) != 1 ) return false ;
100
100
if (include_charsets && IsRecoding () && !recoder_.Serialize (fp)) return false ;
@@ -120,8 +120,7 @@ bool LSTMRecognizer::DeSerialize(const TessdataManager* mgr, TFile* fp) {
120
120
if (fp->FReadEndian (&sample_iteration_, sizeof (sample_iteration_), 1 ) != 1 )
121
121
return false ;
122
122
if (fp->FReadEndian (&null_char_, sizeof (null_char_), 1 ) != 1 ) return false ;
123
- if (fp->FReadEndian (&weight_range_, sizeof (weight_range_), 1 ) != 1 )
124
- return false ;
123
+ if (fp->FReadEndian (&adam_beta_, sizeof (adam_beta_), 1 ) != 1 ) return false ;
125
124
if (fp->FReadEndian (&learning_rate_, sizeof (learning_rate_), 1 ) != 1 )
126
125
return false ;
127
126
if (fp->FReadEndian (&momentum_, sizeof (momentum_), 1 ) != 1 ) return false ;
@@ -207,14 +206,22 @@ void LSTMRecognizer::OutputStats(const NetworkIO& outputs, float* min_output,
207
206
STATS stats (0 , kOutputScale + 1 );
208
207
for (int t = 0 ; t < outputs.Width (); ++t) {
209
208
int best_label = outputs.BestLabel (t, NULL );
210
- if (best_label != null_char_ || t == 0 ) {
209
+ if (best_label != null_char_) {
211
210
float best_output = outputs.f (t)[best_label];
212
211
stats.add (static_cast <int >(kOutputScale * best_output), 1 );
213
212
}
214
213
}
215
- *min_output = static_cast <float >(stats.min_bucket ()) / kOutputScale ;
216
- *mean_output = stats.mean () / kOutputScale ;
217
- *sd = stats.sd () / kOutputScale ;
214
+ // If the output is all nulls it could be that the photometric interpretation
215
+ // is wrong, so make it look bad, so the other way can win, even if not great.
216
+ if (stats.get_total () == 0 ) {
217
+ *min_output = 0 .0f ;
218
+ *mean_output = 0 .0f ;
219
+ *sd = 1 .0f ;
220
+ } else {
221
+ *min_output = static_cast <float >(stats.min_bucket ()) / kOutputScale ;
222
+ *mean_output = stats.mean () / kOutputScale ;
223
+ *sd = stats.sd () / kOutputScale ;
224
+ }
218
225
}
219
226
220
227
// Recognizes the image_data, returning the labels,
0 commit comments