12 #include "allheaders.h"
19 TEST_F(LSTMTrainerTest, EncodesEng) {
20 TestEncodeDecodeBoth(
"eng",
21 "The quick brown 'fox' jumps over: the lazy dog!");
24 TEST_F(LSTMTrainerTest, EncodesKan) {
25 TestEncodeDecodeBoth(
"kan",
"ಫ್ರಬ್ರವರಿ ತತ್ವಾಂಶಗಳೆಂದರೆ ಮತ್ತು ಜೊತೆಗೆ ಕ್ರಮವನ್ನು");
28 TEST_F(LSTMTrainerTest, EncodesKor) {
29 TestEncodeDecodeBoth(
"kor",
30 "이는 것으로 다시 넣을 수는 있지만 선택의 의미는");
33 TEST_F(LSTMTrainerTest, MapCoder) {
34 LSTMTrainer fra_trainer;
35 fra_trainer.InitCharSet(TestDataNameToPath(
"fra/fra.traineddata"));
36 LSTMTrainer deu_trainer;
37 deu_trainer.InitCharSet(TestDataNameToPath(
"deu/deu.traineddata"));
39 std::string kTestStr =
"The quick brown 'fox' jumps over: the lazy dog!";
41 EXPECT_TRUE(deu_trainer.EncodeString(kTestStr.c_str(), &deu_labels));
43 STRING badly_decoded = fra_trainer.DecodeLabels(deu_labels);
45 LOG(
INFO) <<
"bad_str fra=" << bad_str <<
"\n";
46 EXPECT_NE(kTestStr, bad_str);
49 EXPECT_TRUE(fra_trainer.EncodeString(kTestStr.c_str(), &fra_labels));
51 std::vector<int> mapping = fra_trainer.MapRecoder(deu_trainer.GetUnicharset(),
52 deu_trainer.GetRecoder());
54 for (
int i = 0; i < fra_labels.
size(); ++i) {
55 mapped_fra_labels[i] = mapping[fra_labels[i]];
56 EXPECT_NE(-1, mapped_fra_labels[i]) <<
"i=" << i <<
", ch=" << kTestStr[i];
57 EXPECT_EQ(mapped_fra_labels[i], deu_labels[i])
58 <<
"i=" << i <<
", ch=" << kTestStr[i]
59 <<
" has deu label=" << deu_labels[i] <<
", but mapped to "
60 << mapped_fra_labels[i];
63 STRING decoded = deu_trainer.DecodeLabels(mapped_fra_labels);
65 LOG(
INFO) <<
"ok_str deu=" << ok_str <<
"\n";
66 EXPECT_EQ(kTestStr, ok_str);
71 TEST_F(LSTMTrainerTest, ConvertModel) {
73 LSTMTrainer deu_trainer;
74 deu_trainer.InitCharSet(TestDataNameToPath(
"deu/deu.traineddata"));
79 CHECK(mgr.Init(fra_data.c_str()));
80 LOG(
INFO) <<
"Load " << fra_data <<
"\n";
82 CHECK(mgr.ExtractToFile(model_path.c_str()));
83 LOG(
INFO) <<
"Extract " << model_path <<
"\n";
85 CHECK(deu_trainer.TryLoadingCheckpoint(model_path.c_str(), fra_data.c_str()));
86 LOG(
INFO) <<
"Checkpoint load for " << model_path <<
" and " << fra_data <<
"\n";
88 CHECK(deu_trainer.SaveTraineddata(deu_data.c_str()));
89 LOG(
INFO) <<
"Save " << deu_data <<
"\n";
94 Pix* src_pix = pixRead(TestingNameToPath(
"phototest.tif").c_str());
96 api.SetImage(src_pix);
97 std::unique_ptr<char[]> result(api.GetUTF8Text());
102 EXPECT_STREQ(truth_text.c_str(), result.get());
103 pixDestroy(&src_pix);