42static const int kNumTopNErrs = 10;
43static const int kNumTop2Errs = kNumTopNErrs + 20;
44static const int kNumTop1Errs = kNumTop2Errs + 30;
45static const int kNumTopTopErrs = kNumTop1Errs + 25;
46static const int kNumNonReject = 1000;
47static const int kNumCorrect = kNumNonReject - kNumTop1Errs;
50static const int kNumAnswers = kNumNonReject + 2 * (kNumTop2Errs - kNumTopNErrs) +
51 (kNumTop1Errs - kNumTop2Errs) + (kNumTopTopErrs - kNumTop1Errs);
53#ifndef DISABLED_LEGACY_ENGINE
54static bool safe_strto32(
const std::string &str,
int *pResult) {
55 long n = strtol(str.c_str(),
nullptr, 0);
66 : shape_table_(shape_table), num_done_(0), done_bad_font_(false) {
70 false_unichar_id_ = 67;
71 false_shape_ = shape_table_->
AddShape(false_unichar_id_, 25);
82 std::vector<ShapeRating> *results)
override {
85 if (++num_done_ > kNumNonReject) {
91 int shape_id = shape_table_->
FindShape(class_id, font_id);
93 int wrong_id1 = shape_id > 10 ? shape_id - 1 : shape_id + 1;
94 int wrong_id2 = shape_id > 10 ? shape_id - 2 : shape_id + 2;
95 if (num_done_ <= kNumTopNErrs) {
98 }
else if (num_done_ <= kNumTop2Errs) {
101 results->push_back(
ShapeRating(wrong_id2, 0.875f));
103 }
else if (num_done_ <= kNumTop1Errs) {
107 }
else if (num_done_ <= kNumTopTopErrs) {
113 }
else if (!done_bad_font_ && class_id == false_unichar_id_) {
115 results->push_back(
ShapeRating(false_shape_, 1.0f));
116 done_bad_font_ =
true;
121 return results->size();
132 int false_unichar_id_;
145#ifndef DISABLED_LEGACY_ENGINE
148 std::locale::global(std::locale(
""));
172 FLAGS_F =
file::JoinPath(LANGDATA_DIR,
"font_properties").c_str();
176 const char *filelist[] = {tr_file_name.c_str(),
nullptr};
177 std::string file_prefix;
235#ifdef DISABLED_LEGACY_ENGINE
248#ifdef DISABLED_LEGACY_ENGINE
256 if (shape_table_->FindShape(0, -1) < 0) {
257 shape_table_->AddShape(0, 0);
260 auto shape_classifier = std::make_unique<MockClassifier>(shape_table_);
262 std::string accuracy_report;
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');
271 EXPECT_TRUE(safe_strto32(results[
i + 1], &result_values[
i]));
275 int num_samples = master_trainer_->GetSamples()->num_raw_samples();
TEST_F(MasterTrainerTest, Il1Test)
const double kMin1lDistance
#define EXPECT_EQ(val1, val2)
#define EXPECT_GT(val1, val2)
#define EXPECT_GE(val1, val2)
#define EXPECT_TRUE(condition)
std::unique_ptr< MasterTrainer > LoadTrainingData(const char *const *filelist, bool replication, ShapeTable **shape_table, std::string &file_prefix)
const std::vector< std::string > split(const std::string &s, char c)
unsigned AddShape(int unichar_id, int font_id)
int FindShape(int unichar_id, int font_id) const
UNICHAR_ID class_id() const
static std::string JoinPath(const std::string &s1, const std::string &s2)
~MockClassifier() override=default
MockClassifier(ShapeTable *shape_table)
const ShapeTable * GetShapeTable() const override
int ClassifySample(const TrainingSample &sample, Image page_pix, int debug, UNICHAR_ID keep_this, std::vector< ShapeRating > *results) override
~MasterTrainerTest() override
ShapeTable * shape_table_
std::string TestDataNameToPath(const std::string &name)
std::string TmpNameToPath(const std::string &name)
std::unique_ptr< MasterTrainer > master_trainer_