tesseract  5.0.0
mastertrainer_test.cc File Reference
#include "include_gunit.h"
#include "commontraining.h"
#include "errorcounter.h"
#include "log.h"
#include "mastertrainer.h"
#include "shapeclassifier.h"
#include "shapetable.h"
#include "trainingsample.h"
#include "unicharset.h"
#include <string>
#include <utility>
#include <vector>

Go to the source code of this file.

Classes

class  MockClassifier
 
class  MasterTrainerTest
 

Functions

 TEST_F (MasterTrainerTest, Il1Test)
 
 TEST_F (MasterTrainerTest, ErrorCounterTest)
 

Variables

const double kMin1lDistance = 0.25
 

Function Documentation

◆ TEST_F() [1/2]

TEST_F ( MasterTrainerTest  ,
ErrorCounterTest   
)

Definition at line 247 of file mastertrainer_test.cc.

247  {
248 #ifdef DISABLED_LEGACY_ENGINE
249  // Skip test because LoadTrainingData is missing.
250  GTEST_SKIP();
251 #else
252  // Initialize the master_trainer_ from the saved tmp file.
253  LoadMasterTrainer();
254  // Add the space character to the shape_table_ if not already present to
255  // count junk.
256  if (shape_table_->FindShape(0, -1) < 0) {
257  shape_table_->AddShape(0, 0);
258  }
259  // Make a mock classifier.
260  auto shape_classifier = std::make_unique<MockClassifier>(shape_table_);
261  // Get the accuracy report.
262  std::string accuracy_report;
263  master_trainer_->TestClassifierOnSamples(tesseract::CT_UNICHAR_TOP1_ERR, 0, false,
264  shape_classifier.get(), &accuracy_report);
265  LOG(INFO) << accuracy_report.c_str();
266  std::string result_string = accuracy_report.c_str();
267  std::vector<std::string> results = split(result_string, '\t');
268  EXPECT_EQ(tesseract::CT_SIZE + 1, results.size());
269  int result_values[tesseract::CT_SIZE];
270  for (int i = 0; i < tesseract::CT_SIZE; ++i) {
271  EXPECT_TRUE(safe_strto32(results[i + 1], &result_values[i]));
272  }
273  // These tests are more-or-less immune to additions to the number of
274  // categories or changes in the training data.
275  int num_samples = master_trainer_->GetSamples()->num_raw_samples();
276  EXPECT_EQ(kNumCorrect, result_values[tesseract::CT_UNICHAR_TOP_OK]);
277  EXPECT_EQ(1, result_values[tesseract::CT_FONT_ATTR_ERR]);
278  EXPECT_EQ(kNumTopTopErrs, result_values[tesseract::CT_UNICHAR_TOPTOP_ERR]);
279  EXPECT_EQ(kNumTop1Errs, result_values[tesseract::CT_UNICHAR_TOP1_ERR]);
280  EXPECT_EQ(kNumTop2Errs, result_values[tesseract::CT_UNICHAR_TOP2_ERR]);
281  EXPECT_EQ(kNumTopNErrs, result_values[tesseract::CT_UNICHAR_TOPN_ERR]);
282  // Each of the TOPTOP errs also counts as a multi-unichar.
283  EXPECT_EQ(kNumTopTopErrs - kNumTop1Errs, result_values[tesseract::CT_OK_MULTI_UNICHAR]);
284  EXPECT_EQ(num_samples - kNumNonReject, result_values[tesseract::CT_REJECT]);
285  EXPECT_EQ(kNumAnswers, result_values[tesseract::CT_NUM_RESULTS]);
286 #endif
287 }
@ LOG
@ INFO
Definition: log.h:28
const std::vector< std::string > split(const std::string &s, char c)
Definition: helpers.h:41
@ CT_UNICHAR_TOPN_ERR
Definition: errorcounter.h:76
@ CT_UNICHAR_TOP_OK
Definition: errorcounter.h:70
@ CT_UNICHAR_TOP1_ERR
Definition: errorcounter.h:74
@ CT_UNICHAR_TOP2_ERR
Definition: errorcounter.h:75
@ CT_UNICHAR_TOPTOP_ERR
Definition: errorcounter.h:77
@ CT_FONT_ATTR_ERR
Definition: errorcounter.h:82
@ CT_OK_MULTI_UNICHAR
Definition: errorcounter.h:78
@ CT_NUM_RESULTS
Definition: errorcounter.h:84

◆ TEST_F() [2/2]

TEST_F ( MasterTrainerTest  ,
Il1Test   
)

Definition at line 234 of file mastertrainer_test.cc.

234  {
235 #ifdef DISABLED_LEGACY_ENGINE
236  // Skip test because LoadTrainingData is missing.
237  GTEST_SKIP();
238 #else
239  // Initialize the master_trainer_ and load the Arial tr file.
240  LoadMasterTrainer();
241  VerifyIl1();
242 #endif
243 }

Variable Documentation

◆ kMin1lDistance

const double kMin1lDistance = 0.25

Definition at line 141 of file mastertrainer_test.cc.