48 {
49 const int fontsize = it->sample_set()->NumFonts();
50 ErrorCounter counter(classifier->GetUnicharset(), fontsize);
51 std::vector<UnicharRating> results;
52
53 clock_t start = clock();
54 unsigned total_samples = 0;
55 double unscaled_error = 0.0;
56
57 int error_samples = report_level > 3 ? report_level * report_level : 0;
58
59 for (it->Begin(); !it->AtEnd(); it->Next()) {
60 TrainingSample *mutable_sample = it->MutableSample();
61 int page_index = mutable_sample->page_num();
62 Image page_pix =
63 0 <= page_index && page_index < page_images.size() ? page_images[page_index] : nullptr;
64
65 classifier->UnicharClassifySample(*mutable_sample, page_pix, 0, INVALID_UNICHAR_ID, &results);
66 bool debug_it = false;
67 int correct_id = mutable_sample->class_id();
68 if (counter.unicharset_.has_special_codes() &&
71
72 debug_it = counter.AccumulateJunk(report_level > 3, results, mutable_sample);
73 } else {
74 debug_it = counter.AccumulateErrors(report_level > 3, boosting_mode, fontinfo_table, results,
75 mutable_sample);
76 }
77 if (debug_it && error_samples > 0) {
78
79 tprintf(
"Error on sample %d: %s Classifier debug output:\n", it->GlobalSampleIndex(),
80 it->sample_set()->SampleToString(*mutable_sample).c_str());
81#ifndef GRAPHICS_DISABLED
82 classifier->DebugDisplay(*mutable_sample, page_pix, correct_id);
83#endif
84 --error_samples;
85 }
86 ++total_samples;
87 }
88 const double total_time = 1.0 * (clock() - start) / CLOCKS_PER_SEC;
89
90 unscaled_error = counter.ReportErrors(report_level, boosting_mode, fontinfo_table, *it,
91 unichar_error, fonts_report);
92 if (scaled_error != nullptr) {
93 *scaled_error = counter.scaled_error_;
94 }
95 if (report_level > 1 && total_samples > 0) {
96
97 tprintf(
"Errors computed in %.2fs at %.1f μs/char\n", total_time,
98 1000000.0 * total_time / total_samples);
99 }
100 return unscaled_error;
101}
void tprintf(const char *format,...)