1
+ // (C) Copyright 2017, Google Inc.
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ // http://www.apache.org/licenses/LICENSE-2.0
6
+ // Unless required by applicable law or agreed to in writing, software
7
+ // distributed under the License is distributed on an "AS IS" BASIS,
8
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9
+ // See the License for the specific language governing permissions and
10
+ // limitations under the License.
1
11
2
12
// Generating the training data:
3
13
// If the format of the lstmf (ImageData) file changes, the training data will
4
- // have to be regenerated as follows:
5
- // ./tesseract/text2image --xsize=800 --font=Arial \
6
- // --text=tesseract/testdata/lstm_training.txt --leading=32 \
7
- // --outputbase=tesseract/testdata/lstm_training.arial
8
- // ./tesseract tesseract/testdata/lstm_training.arial.tif \
9
- // tesseract/testdata/lstm_training.arial lstm.train \
10
- // --pageseg_mode=6
14
+ // have to be regenerated as follows:
15
+ //
16
+ // Use --xsize 800 for text2image to be similar to original training data.
17
+ //
18
+ // src/training/tesstrain.sh --fonts_dir /usr/share/fonts --lang eng --linedata_only --noextract_font_properties --langdata_dir ../langdata_lstm --tessdata_dir ../tessdata --output_dir ~/tesseract/test/testdata --fontlist "Arial" --maxpages 10
19
+ //
11
20
12
- #include " tesseract/unittest/ lstm_test.h"
21
+ #include " lstm_test.h"
13
22
14
23
namespace tesseract {
15
24
@@ -19,15 +28,17 @@ TEST_F(LSTMTrainerTest, BasicTest) {
19
28
SetupTrainer (
20
29
" [1,32,0,1 Ct5,5,16 Mp4,4 Ct1,1,16 Ct3,3,128 Mp4,1 Ct1,1,64 S2,1 "
21
30
" Ct1,1,64O1c1]" ,
22
- " no-lstm" , " eng.unicharset" , " lstm_training.arial .lstmf" , false , false ,
31
+ " no-lstm" , " eng/eng .unicharset" , " eng.Arial.exp0 .lstmf" , false , false ,
23
32
2e-4 , false );
24
- double non_lstm_err = TrainIterations (kTrainerIterations * 3 / 2 );
33
+ double non_lstm_err = TrainIterations (kTrainerIterations * 3 );
25
34
EXPECT_LT (non_lstm_err, 98 );
35
+ LOG (INFO) << " ********** Expected < 98 ************" ;
26
36
27
37
// A basic single-layer, single direction LSTM.
28
38
SetupTrainerEng (" [1,1,0,32 Lfx100 O1c1]" , " 1D-lstm" , false , false );
29
39
double lstm_uni_err = TrainIterations (kTrainerIterations * 2 );
30
40
EXPECT_LT (lstm_uni_err, 86 );
41
+ LOG (INFO) << " ********** Expected < 86 ************" ;
31
42
// Beats the convolver. (Although it does have a lot more weights, it still
32
43
// iterates faster.)
33
44
EXPECT_LT (lstm_uni_err, non_lstm_err);
@@ -41,14 +52,15 @@ TEST_F(LSTMTrainerTest, ColorTest) {
41
52
double lstm_uni_err = TrainIterations (kTrainerIterations );
42
53
EXPECT_LT (lstm_uni_err, 85 );
43
54
EXPECT_GT (lstm_uni_err, 66 );
55
+ LOG (INFO) << " ********** Expected > 66 ** < 85 ************" ;
44
56
}
45
57
46
58
TEST_F (LSTMTrainerTest, BidiTest) {
47
59
// A basic single-layer, bi-di 1d LSTM.
48
60
SetupTrainerEng (" [1,1,0,32 Lbx100 O1c1]" , " bidi-lstm" , false , false );
49
61
double lstm_bi_err = TrainIterations (kTrainerIterations );
50
62
EXPECT_LT (lstm_bi_err, 75 );
51
-
63
+ LOG (INFO) << " ********** Expected < 75 ************ " ;
52
64
// Int mode training is dead, so convert the trained network to int and check
53
65
// that its error rate is close to the float version.
54
66
TestIntMode (kTrainerIterations );
@@ -63,6 +75,7 @@ TEST_F(LSTMTrainerTest, Test2D) {
63
75
double lstm_2d_err = TrainIterations (kTrainerIterations );
64
76
EXPECT_LT (lstm_2d_err, 98 );
65
77
EXPECT_GT (lstm_2d_err, 90 );
78
+ LOG (INFO) << " ********** Expected > 90 ** < 98 ************" ;
66
79
// Int mode training is dead, so convert the trained network to int and check
67
80
// that its error rate is close to the float version.
68
81
TestIntMode (kTrainerIterations );
@@ -76,6 +89,7 @@ TEST_F(LSTMTrainerTest, TestAdam) {
76
89
" 2-D-2-layer-lstm" , false , true );
77
90
double lstm_2d_err = TrainIterations (kTrainerIterations );
78
91
EXPECT_LT (lstm_2d_err, 70 );
92
+ LOG (INFO) << " ********** Expected < 70 ************" ;
79
93
TestIntMode (kTrainerIterations );
80
94
}
81
95
@@ -86,6 +100,7 @@ TEST_F(LSTMTrainerTest, SpeedTest) {
86
100
" O1c1]" ,
87
101
" 2-D-2-layer-lstm" , false , true );
88
102
TrainIterations (kTrainerIterations );
103
+ LOG (INFO) << " ********** *** ************" ;
89
104
}
90
105
91
106
// Tests that two identical networks trained the same get the same results.
@@ -121,6 +136,7 @@ TEST_F(LSTMTrainerTest, DeterminismTest) {
121
136
EXPECT_FLOAT_EQ (lstm_2d_err_a, lstm_2d_err_b);
122
137
EXPECT_FLOAT_EQ (act_error_a, act_error_b);
123
138
EXPECT_FLOAT_EQ (char_error_a, char_error_b);
139
+ LOG (INFO) << " ********** *** ************" ;
124
140
}
125
141
126
142
// The baseline network against which to test the built-in softmax.
@@ -130,6 +146,7 @@ TEST_F(LSTMTrainerTest, SoftmaxBaselineTest) {
130
146
double lstm_uni_err = TrainIterations (kTrainerIterations * 2 );
131
147
EXPECT_LT (lstm_uni_err, 60 );
132
148
EXPECT_GT (lstm_uni_err, 48 );
149
+ LOG (INFO) << " ********** Expected > 48 ** < 60 ************" ;
133
150
// Check that it works in int mode too.
134
151
TestIntMode (kTrainerIterations );
135
152
// If we run TestIntMode again, it tests that int_mode networks can
@@ -148,6 +165,7 @@ TEST_F(LSTMTrainerTest, SoftmaxTest) {
148
165
SetupTrainerEng (" [1,1,0,32 LS96]" , " Lstm-+-softmax" , false , true );
149
166
double lstm_sm_err = TrainIterations (kTrainerIterations * 2 );
150
167
EXPECT_LT (lstm_sm_err, 49.0 );
168
+ LOG (INFO) << " ********** Expected < 49 ************" ;
151
169
// Check that it works in int mode too.
152
170
TestIntMode (kTrainerIterations );
153
171
}
@@ -159,6 +177,7 @@ TEST_F(LSTMTrainerTest, EncodedSoftmaxTest) {
159
177
SetupTrainerEng (" [1,1,0,32 LE96]" , " Lstm-+-softmax" , false , true );
160
178
double lstm_sm_err = TrainIterations (kTrainerIterations * 2 );
161
179
EXPECT_LT (lstm_sm_err, 62.0 );
180
+ LOG (INFO) << " ********** Expected < 62 ************" ;
162
181
// Check that it works in int mode too.
163
182
TestIntMode (kTrainerIterations );
164
183
}
0 commit comments